Data flow windowing and triggering

ABSTRACT

A method includes receiving data corresponding one of streaming data or batch data and a content of the received data for computation. The method also includes determining an event time of the data for slicing the data, determining a processing time to output results of the received data, and emitting at least a portion of the results of the received data based on the processing time and the event time.

CROSS REFERENCE TO RELATED APPLICATIONS

This U.S. patent application claims priority under 35 U.S.C. § 119(e) toU.S. Provisional Application 62/074,271, filed Nov. 3, 2014, and U.S.Provisional Application 62/201,441, filed Aug. 5, 2015. The disclosuresof these prior applications are considered part of the disclosure ofthis application and are hereby incorporated by reference in theirentireties.

TECHNICAL FIELD

This disclosure relates to data flow windowing and triggering.

SUMMARY

One aspect of the disclosure provides a method for data flow windowingand triggering. The method includes receiving data corresponding one ofstreaming data or batch data at data processing hardware, determining,using the data processing hardware, a content of the received data forcomputation, determining, using the data processing hardware, an eventtime of the data for slicing the data, and determining a processing timeto output results of the received data using the data processinghardware. The method also includes emitting at least a portion of theresults of the received data based on the processing time and the eventtime.

Implementations of the disclosure may include one or more of thefollowing optional features. In some implementations, the methodincludes grouping, using the data processing hardware, the received datawindows based on the event time. The windows may include one of fixedwindows, defined by a static time period, sliding windows defined by atime period and a slide period, session windows defined by a timeoutgap, or user-defined windows defined by a pair of functions. Each fixedwindow may be applied across all of the data within the associated timeperiod. Each sliding window may be applied across all of the data withinthe associated time period and associated with a start time separatedfrom a start time of an immediately successive window by the slideperiod. Moreover, each session window may be applied across a subset ofthe data occurring within a span of time less than the associatedtimeout gap. In some examples, the method includes assigning, using thedata processing hardware, a mergeable window for each element of thereceived data, each element including an associated input timestamp andeach mergeable window extending a predefined range of time beyond theinput timestamp for the associated window. The method may also includemerging, using the data processing hardware, two or more of themergeable windows belonging to a same key that overlap into a singlemerged window, and setting, using the data processing hardware, anassociated output timestamp for each element to a value greater than orequal to an earliest time in the associated merged window or theassociated mergeable window. The single merged window may include anassociated range of time greater than the predefined range of time.

When the received data corresponds to streaming data, the method mayinclude grouping, using the data processing hardware, the streaming datainto windows and setting, using the data processing hardware, an inputtimestamp on an element of the streaming data. When the input timestampon the element occurs earlier than a watermark, the method may includedetermining, using the data processing hardware, the streaming dataincluding late streaming data, and one of dropping the late streamingdata or allowing the late streaming data by creating a duplicate windowin an output for the late streaming data.

In some examples, the method includes grouping, using the dataprocessing hardware, a first subset of the received data into a window,the window defining a sub-event time of the data subset, aggregating,using the data processing hardware, a first result of the first datasubset for the window, and determining, using the data processinghardware, a trigger time to emit the first aggregated result of thefirst data subset. The trigger time may include at least one of: when awatermark reaches an end of the window; every threshold number ofseconds of a walltime; after receiving a punctuation record thatterminates the window; every threshold number of records; afterarbitrary user logic decides to trigger; or after an arbitrarycombination of concrete triggers.

When determining the trigger time to emit the first aggregated result ofthe first data subset, the method may include discarding, using the dataprocessing hardware, the first aggregated result from use whenaggregating results of later subsets of the received data. Whendetermining the trigger time to emit the first aggregated result of thefirst data subset, the method may also include storing a copy of thefirst aggregated result in a persistent state within memory hardware incommunication with the data processing hardware, and refining, by thedata processing hardware, a next aggregate result of a later subset withthe first aggregated result. When determining the trigger time to emitthe first aggregated result of the first data subset, the method mayfurther include storing a copy of the first aggregated result in apersistent state within memory hardware in communication with the dataprocessing hardware. When a next aggregated result of a later subset isassociated with the same window emits, the method may include emitting aretraction of the first aggregated result and emitting a combinedsession result for the window.

In some implementations, the method includes receiving, at the dataprocessing hardware, a late data point after grouping the first datasubset into the window, the late data point related to the window, anddiscarding, using the data processing hardware, the late data point. Themethod may also include receiving, at the data processing hardware, alate data point after grouping the first data subset into the window,the late data point related to the window, and accumulating, using thedata processing hardware, the late data point into the window to refinethe first aggregated result with the late data point. The method mayfurther include receiving, at the data processing hardware, a late datapoint after grouping the first data subset into the window, the latedata point related to the window, aggregating, using the data processinghardware, a combined result of the first data subset and the late datapoint, and emitting the combined result.

Another aspect of the disclosure provides a system for data flowwindowing and triggering. The system includes data processing hardwareand memory hardware in communication with the data processing hardware.The memory hardware stores instructions that when executed on the dataprocessing hardware, cause the data processing hardware to performoperations. The operations include: receiving data corresponding to oneof streaming data or batch data; determining a content of the receiveddata for computation; determining an event time of the data for slicingthe data; determining a processing time to output results of thereceived data; and emitting at least a portion of the results of thereceived data based on the processing time and the event time.

This aspect may include one or more of the following optional features.In some examples, the operations further include grouping the receiveddata into windows based on the event time. The windows include one offixed windows defined by a static time period, sliding windows definedby a time period and a slide period, session windows defined by atimeout gap, or user-defined windows defined by a pair functions. Eachfixed window may be applied across all of the data within the associatedtime period, each sliding window may be applied across all of the datawithin the associated time period and associated with a start timeseparated from a start time of an immediately successive window by theslide period, and each session window may be applied across a subset ofthe data occurring within a span of time less than the associatedtimeout gap.

The operations may further include assigning a mergeable window for eachelement of the received data, each element including an associated inputtimestamp and each mergeable window extending a predefined range of timebeyond the input timestamp for the associated window. The operations mayalso include merging two or more of the mergeable windows belonging to asame key that overlap into a single merged window and setting anassociated output timestamp for each element to a value greater than orequal to an earliest time in the associated merged window or theassociated mergeable window. The single merged window may include anassociated range of time greater than the predefined range of time.

When the received data corresponds to streaming data, the operations mayfurther include grouping, using the data processing hardware, thestreaming data into windows and setting, using the data processinghardware, an input timestamp on an element of the streaming data. Whenthe input timestamp on the element occurs earlier than a watermark, theoperations may include determining, using the data processing hardware,the streaming data comprises late streaming data, and one of: droppingthe late streaming data or allowing the late streaming data by creatinga duplicate window in an output for the late streaming data.

In some examples, the operations further include grouping a first subsetof the received data into a window, the window defining a sub-event timeof the data subset, aggregating a first result of the first data subsetfor the window, and determining a trigger time to emit the firstaggregated result of the first data subset. The trigger time may includeat least one of: when a watermark reaches an end of the window; everythreshold number of seconds of a walltime; after receiving a punctuationrecord that terminates the window; every threshold number of records;after arbitrary user logic decides to trigger; or after an arbitrarycombination of concrete triggers.

When determining the trigger time to emit the first aggregated result ofthe first data subset, the operations may include discarding the firstaggregated result from use when aggregating results of later subsets ofthe received data. When determining the trigger time to emit the firstaggregated result of the first data subset, the operations may alsoinclude storing a copy of the first aggregated result in a persistentstate within memory hardware in communication with the data processinghardware, and refining a next aggregate result of a later subset withthe first aggregated result. When determining the trigger time to emitthe first aggregated result of the first data subset, the operations mayfurther include storing a copy of the first aggregated result in apersistent state within memory hardware in communication with the dataprocessing hardware. When a next aggregated result of a later subset isassociated with the same window emits, the operations may includeemitting a retraction of the first aggregated result and emitting acombined session result for the window.

In some examples, the operations include receiving a late data pointafter grouping the first data subset into the window, the late datapoint related to the window, and discarding the late data point. Theoperations may also include receiving a late data point after groupingthe first data subset into the window, the late data point related tothe window, and accumulating the late data point into the window torefine the first aggregated result with the late data point. Theoperations may further include receiving a late data point aftergrouping the first data subset into the window, the late data pointrelated to the window, aggregating a combined result of the first datasubset and the late data point, and emitting the combined result.

The details of one or more implementations of the disclosure are setforth in the accompanying drawings and the description below. Otheraspects, features, and advantages will be apparent from the descriptionand drawings, and from the claims.

DESCRIPTION OF DRAWINGS

FIGS. 1A and 1B are schematic views of an example streaming computationsystem.

FIG. 2 is a schematic view of an example windowing ApplicationProgramming Interface (API) of the streaming computation system of FIG.1.

FIG. 3 is an example of fixed, sliding, and session windows.

FIG. 4 is an example plot of a window time domain skew.

FIG. 5 is an example of a window merging operation.

FIG. 6A is an example plot of window time domain skew for data pointinputs.

FIG. 6B is an example plot showing an output result within a singleglobal window.

FIG. 6C is an example plot showing output results accumulating overregions of processing time.

FIG. 6D is an example plot showing output results from independentregions of processing time.

FIG. 6E is an example plot showing output results from independentregions of processing time.

FIG. 6F is an example plot showing data point inputs grouped withinfixed windows and output results emitted from the fixed windows as awatermark advances.

FIG. 6G is an example plot showing data point inputs grouped withinfixed windows and output results emitted from the fixed windows insuccessive micro-batches.

FIG. 6H is an example plot showing a late data point updating an outputresult of a fixed window.

FIG. 6I is an example plot showing output results based onprocessing-time-based triggers.

FIG. 6J is an example plot showing data point inputs grouped withinsession windows and combined output results emitted from combinedsession windows.

FIG. 7 is a schematic view of an example computing device executing anysystems or methods described herein.

Like reference symbols in the various drawings indicate like elements.

DETAILED DESCRIPTION

Batch data processing is the execution of programs (aka jobs) on acomputer without manual intervention, i.e., without human intervention.The program parameters are predefined via scripts, command-linearguments, control files, or job control language. A program takes a setof data files as input, and then processes the data before producing aset of output files. The term “batch processing” refers to input datacollected into batches or sets of records and each batch is processed asa unit. The output is also a batch that is reused for computations.

Large-scale batch data processing is known in the industry. A programmerwrites code that describes some sort of computation, and then runs thatcode over a finite dataset to produce a result. If the computation inquestion happens to involve aggregation by time (e.g. grouping intofixed windows, or calculating per-user sessions), then the programmereither processes the data in window-sized batches (for simple cases likefixed windows), or the programmer incorporates the windowing logic intoyour computation logic (for complicated cases like user sessions).Time-based aggregation is actually relatively common, since it is veryuseful in analyzing user behavior patterns.

When a programmer is dealing with streaming data, which is a relativelynew field compared to batch processing, the programmer has anessentially unbounded set of data over which he/she wants to perform asimilar computation. But since the data lacks finite boundaries, theprogrammer needs to use either (1) online approximation algorithms(e.g., approximate Top N), or (2) determine a way to chop up the datastream into pieces.

Online approximation algorithms approach can be very useful for someapplications, but since the results are approximate, they are not acomplete replacement for the precise results of batch computations. As aresult, the programmer ends up running both streaming and batch systemsside-by-side (e.g., Lambda Architecture): streaming for low latency andbatch for precise, repeatable results.

Chopping up the data stream into finite pieces yields the opportunity tocalculate precise results in a streaming fashion. In addition tocomputing some aggregate, the programmer also has to solve the problemof where to slice up the data stream and when to emit the results. Moststreaming systems take the approach of automatically chopping the datastream up into fixed windows based on the time the data arrives in thesystem (e.g., the programmer requests five-minute windows, and theprogrammer buffers up five minutes of data as it is received and thenprocesses the data). This approach has two major downsides. A firstdownside, unlike the event-time based windows in most batch processingsystems, which accurately reflect the times at which events happened, isthat the walltime windows reflect only the time that data arrived in thesystem. In a healthy system, this will possibly be a reasonably closeapproximation of event time windows, but there is no guarantee of that,and when data is generated by a large set of disparate processes (e.g.,a distributed set of web frontends), it is quite likely that theprogrammer will have times where huge swaths of data show up in anordering that is not like the actual event time ordering. Thus, theprogrammer's streaming system becomes a low-latency approximation thatmust be backed up by a batch system to provide precise results. A seconddownside is that the windowing function applied to the data is the sameacross all data. Thus, the programmer has no way of generating customerwindows for subsets of the data, e.g., per-user sessions that capturebursts of activity for a specific user. So the programmer can onlysupport a subset of the use cases the programmer could in batch.

MillWheel (and now WindMill, the Dataflow streaming backend), which is aframework for building low-latency data-processing applications, seemsto be the only streaming system that does not have the aforementionedlimitations, based on its strong consistency guarantees and powerful API(Application programming interface). MillWheel's API allows theprogrammer to buffer data in arbitrary ways based on event time,emitting results whenever the programmer deems useful, including afterperiods of walltime like other systems, but also in a data driven manner(e.g., receipt of a punctuation record) or after the system believes alldata up to a given event time has been received (watermarks/cursors).The programmer can build a streaming data processing system withMillWheel that calculates exact results and completely replaces a batchsystem generating the same output, but with much lower latency.

The big downside of the MillWheel API is that it is very low level. Itprovides all the right building blocks, but does not abstract them in away that makes it easy for a programmer to write new computations, orcompose existing libraries to build new computations. Flume is adistributed, reliable, and available service for efficiently collecting,aggregating, and moving large amounts of log data. Flume has a simpleand flexible architecture based on streaming data flows. In addition,Flume architecture is much more high level than MillWheel architecture,making it very easy to link and compose computational building blocksinto something powerful but understandable. However, the batch Flume APIdoes not really fit well with the streaming paradigm, because it has nonotion of how to chop up unbounded streams of data for processing.Therefore, there is a need for APIs that chop up unbounded streams ofdata for processing (and the underlying architecture that supportsthem).

Referring to FIGS. 1A and 1B, in some implementations, a streamingcomputation system 100 includes an aggregation API 200, a windowing API300, and a triggers API 400, where each API focuses on a separateportion of the streaming computation process.

The aggregation API 200 focuses on what the programmer is computing, forexample, a sum, or a list of top N values. The windowing API 300 focuseson where (in event time) the programmer chooses to slice up theunbounded stream of data 10 (e.g., fixed windows 330 or sessions 350(FIG. 3)). The triggers API 400 focuses on when (in processing time) theprogrammer chooses to emit the aggregate results 20 for a given windowof data 10.

The aggregation API 200 is essentially the batch API that already existsin Flume. The programmer defines what computation to perform as data 10comes in, and generate a result 20 in response thereto. The windowingAPI 300 allows the programmer to define which windows a given datum(from the entered data 10) falls into. Additionally, when grouping data10 together by key (e.g. by user), the windowing API 300 allows theprogrammer to merge windows, which allows the programmer to build updynamic, data-driven windows like sessions. The triggers API 400 thenallows the programmer to define when the aggregate results 20 for awindow are emitted. Examples might be: when the watermark has reachedthe end of the window (the canonical time-based aggregation model inMillWheel); every N seconds of walltime (e.g., for a system that caresmore about freshness than completeness in results 20); after receiving apunctuation record that terminates the window; every threshold number ofrecords; after arbitrary user logic decides to trigger; or any arbitrarycombination of concrete triggers (e.g., initially when the watermarkreaches the end of the window, and then once every minute any time latedata 20 behind the watermark arrives, allowing for data 20 to be updatedor changed after the fact).

As far as expressiveness, the streaming computation system 100 providesimplementation clarity, because when implementing a function for one ofthe three APIs 200, 300, 400, the programmer focuses simply on thespecific task at hand (Aggregation, Windowing, or Triggering), which isan improvement over prior system such as MillWheel (and other systems),where the programmer has to conflate the three, leading to more complexcode that is harder to read and maintain. The streaming computationsystem 100 may execute on data storage hardware 710 (FIG. 7) executingon a computing device 700 (FIG. 7). The streaming computation system 100provides composability, because the programmer can mix and matchfunctions from the three APIs 200, 300, 400 to get the precise type ofcomputation needed. An aggregation function 210 to compute a sum can beused with a windowing function 310 to build sessions and a triggerfunction 410 to produce results 20 when the watermark reaches the end ofthe window. The same aggregation function 210 can be used to calculatesums over fixed windows of time, each containing ten records, just bychanging the windowing and trigger functions 310, 410. Therefore, thestreaming computation system 100 (which works in batch mode), allows aprogrammer to build complex, yet understandable and maintainablesystems, that precisely calculate the results 20 that the programmerwants. Therefore, the programmer can write a code using the streamingcomputation system 100, and allow the system 100 to execute in streamingmode to get low latency results, or in batch mode to do massive scalebackfills or perform some one-off calculations. Therefore, the system100 provides multiple benefits including, but not limited to,decomposition of the streaming computation into three axes of what(aggregation API 200), where in event time (windowing API 300), and when(triggers API 400), with attendant APIs and (non-trivial)implementations, and unification of batch and streaming semantics underone common umbrella.

Windowing API 300:

Referring to FIG. 2, the windowing API 300 groups streaming data 10 intofinite windows 22 (fixed windows 330, sessions 350, and sliding windows340 (FIG. 3)) for further processing and aggregation. The windowing API300 may also group streaming data 10 into user-defined windows definedby a pair of functions. The pair of functions may include (1)assignWindows to assign a given element to a set of windows; and (2)mergeWindows to optionally merge a specified subset of windows atgrouping time. Windowing slices up a dataset 10 into finite chunks forprocessing as a group. When dealing with unbounded data 10, windowing isrequired for some operations (to delineate finite boundaries in mostforms of grouping: aggregation, outer joins, time-bounded operations,etc.), and unnecessary for others (filtering, mapping, inner joins,etc.). For bounded data, windowing is essentially optional, though stilla semantically useful concept in many situations (e.g. back-fillinglarge scale updates to portions of a previously computed unbounded datasource). Windowing is effectively always time based; while many systemssupport tuple-based windowing, this is essentially time-based windowingover a logical time domain where elements in order have successivelyincreasing logical timestamps. Windows may be either aligned, i.e.applied across all the data for the window of time in question, orunaligned, i.e. applied across only specific subsets of the data (e.g.per key) for the given window of time. FIG. 3 highlights three of themajor types of windows encountered when dealing with unbounded data.

Fixed windows 330 (sometimes called tumbling windows) are defined by astatic window size, e.g. hourly windows or daily windows. They aregenerally aligned, i.e. every window applies across all of the data 10for the corresponding period of time. For the sake of spreading windowcompletion load evenly across time, they are sometimes unaligned byphase shifting the windows for each key by some random value.

Sliding windows 320 are defined by a window size and slide period, e.g.hourly windows starting every minute. The period may be less than thesize, which means the windows may overlap. Sliding windows are alsotypically aligned; even though the diagram is drawn to give a sense ofsliding motion, all five windows would be applied to all three keys inthe diagram, not just Window 3. Fixed windows are really a special caseof sliding windows where size equals period.

Sessions 330 are windows that capture some period of activity over asubset of the data, in this case per key. Typically they are defined bya timeout gap. Any events that occur within a span of time less than thetimeout are grouped together as a session. Sessions are unalignedwindows. For example, Window 2 applies to Key 1 only, Window 3 to Key 2only, and Windows 1 and 4 to Key 3 only.

When processing data 10 which relate to events in time, there are twoinherent domains of time to consider. The two domains of interest are,Event Time and Processing Time. Event Time is the time at which theevent itself actually occurred, i.e. a record of system clock time (forwhatever system generated the event) at the time of occurrence.Processing Time is the time at which an event is observed at any givenpoint during processing within the pipeline, i.e. the current timeaccording to the system clock. Note that we make no assumptions aboutclock synchronization within a distributed system.

Event time for a given event essentially never changes, but processingtime changes constantly for each event as it flows through the pipelineand time marches ever forward. This is an important distinction when itcomes to robustly analyzing events in the context of when they occurred.

During processing, the realities of the systems in use (communicationdelays, scheduling algorithms, time spent processing, pipelineserialization, etc.) result in an inherent and dynamically changingamount of skew between the two domains. Global progress metrics, such aspunctuations or watermarks, provide a good way to visualize this skew.For our purposes, we'll consider something like MillWheel's watermark,which is a lower bound (often heuristically established) on event timesthat have been processed by the pipeline. Notions of completeness aregenerally incompatible with correctness, so watermarks are not relied onas such. Watermarks do, however, provide a useful notion of when thesystem thinks it likely that all data up to a given point in event timehave been observed, and thus find application in not only visualizingskew, but in monitoring overall system health and progress, as well asmaking decisions around progress that do not require complete accuracy,such as basic garbage collection policies.

In an ideal world, time domain skew would always be zero and theprocessing of events would occur immediately as they happen. Reality isnot so favorable, however, and often results in a non-zero time domainskew. FIG. 4 shows an example time domain skew where the X-axis denotes“event time” and the Y-axis denotes “processing time”. Starting around12:00, an actual watermark starts to skew more away from an idealwatermark as the pipeline lags, diving back close to the ideal watermark at event time around 12:02, then lagging behind again noticeably bythe time 12:03 rolls around. This dynamic variance in skew is verycommon in distributed data processing systems, and will play a big rolein defining what functionality is necessary for providing correct,repeatable results.

The formal model for the system is explained and its semantics aregeneral enough to subsume the standard batch, micro-batch, and streamingmodels, as well as the hybrid streaming and batch semantics of theLambda Architecture. For code examples, we will use a simplified variantof the Dataflow Java SDK, which itself is an evolution of the FlumeJavaAPI.

To begin with, let us consider primitives from the classic batch model.The Dataflow SDK has two core transforms that operate on the (key,value) pairs flowing through the system ParDo and GroupByKey.

ParDo is for generic parallel processing. Each input element to beprocessed (which itself may be a finite collection) is provided to auser-defined function (called a DoFn in Dataflow), which can yield zeroor more output elements per input. For example, consider an operationwhich expands all prefixes of the input key, duplicating the valueacross them:

GroupByKey is for key-grouping (key, value) pairs. As for exampleoperation.

The ParDo operation operates element-wise on each input element, andthus translates naturally to unbounded data. The GroupByKey operation,on the other hand, collects all data for a given key before sending themdownstream for reduction. If the input source is unbounded, we have noway of knowing when it will end. The common solution to this problem isto window the data.

Systems which support grouping typically redefine their GroupByKeyoperation to essentially be GroupByKeyAnd-Window. Our primarycontribution here is support for unaligned windows, for which there aretwo key insights. The first is that it is simpler to treat all windowingstrategies as unaligned from the perspective of the model, and allowunderlying implementations to apply optimizations relevant to thealigned cases where applicable. The second is that windowing can bebroken apart into two related operations:

Set<Window>AssignWindows(T datum), which assigns the element to zero ormore windows.

Set<Window>MergeWindows(Set<Window>windows), which merges windows atgrouping time. This allows data-driven windows to be constructed overtime as data arrive and are grouped together.

For any given windowing strategy, the two operations are intimatelyrelated; sliding window assignment requires sliding window merging,sessions window assignment requires sessions window merging, etc.

Note that, to support event-time windowing natively, instead of passing(key, value) pairs through the system, we now pass (key, value, eventtime, window) 4-tuples. Elements are provided to the system withevent-time times-tamps (which may also be modified at any point in thepipeline), and are initially assigned to a default global window,covering all of event time, providing semantics that match the defaultsin the standard batch model.

From the system perspective, window assignment creates a new copy of theelement in each of the windows to which it has been assigned. Forexample, consider windowing a dataset by sliding windows of two-minutewidth and one-minute period, as shown below (for brevity, timestamps aregiven in HH:MM format).

In this case, each of the two (key, value) pairs is duplicated to existin both of the windows that overlapped the element's timestamp. Sincewindows are associated directly with the elements to which they belong,window assignment may happen anywhere in the pipeline before grouping isapplied. This is important, as the grouping operation may be buriedsomewhere downstream inside a composite transformation (e.g.Sum.integersPerKey( )).

Window merging occurs as part of the GroupByKeyAnd-Window operation, andis best explained in the context of the example window merging operationof FIG. 5. FIG. 5 uses window sessions (also referred to as “sessionwindowing”) for four example data points, three for k1 and one for k2,as they are windowed by session, with a 30-minute session timeout. Allare initially placed in a default global window by the system. Thesessions implementation of AssignWindows puts each element into a singlewindow that extends 30 minutes beyond its own times-tamp; this windowdenotes the range of time into which later events can fall if they areto be considered part of the same session. Thereafter, theGroupByKeyAndWindow operation may commence, which is really a five-partcomposite operation:

DropTimestamps—Drops element timestamps, as only the window is relevantfrom here on out. GroupByKey—Groups (value, window) tuples by key.MergeWindows—Merges the set of currently buffered windows for a key. Theactual merge logic is defined by the windowing strategy. In this case,the windows for v1 and v4 overlap, so the sessions windowing strategymerges them into a single new, larger session, as indicated in bold.GroupAlsoByWindow—For each key, groups values by window. After mergingin the prior step, v1 and v4 are now in identical windows, and thus aregrouped together at this step. ExpandToElements—Expands per-key,per-window groups of values into (key, value, event time, window)tuples, with new per-window timestamps. In this example, the timestampis set to the end of the window, but any timestamp greater than or equalto the timestamp of the earliest event in the window is valid withrespect to watermark correctness.

The following function of using windowing in practice to calculate keyedinteger sums could be accomplished using the Cloud Dataflow SDK and thefollowing:

PCollection<KV<String, Integer>>input=IO.read( . . . );

PCollection<KV<String, Integer>>output=input

.apply(Sum.integersPerKey( ));

A second example can be accomplished using windowed sessions with a30-minute timeout as in FIG. 5 using a single window into call beforeimitating the summation as per the example below.

PCollection<KV<String, Integer>>input=IO.read( . . . );

PCollection<KV<String, Integer>>output=input

.apply(Window.into(Sessions.withGapDuration(Duration.standardMinutes(30))))

.apply(Sum.integersPerKey( ));

The windowing API 300 supports Cloud Dataflow for both streaming andbatch modes. Windowing API semantics may include a high-level model ofwindowing such as, but not limited to, Window.into which assignselements into a set of windows, and GroupByKey that treats the windowson the input elements as secondary keys, and so groups by (key, window)pairs. The following are windowing examples:

Notation:

<Datum, Timestamp, Window Set>

G is the global window, GBF is the global WindowingFn, [t₁, t₂) is anIntervalbucket representing that time interval.

FixedWindows:

Sliding Windows:

Sessions:

General Case, with SomeUnspecifiedCrazyWindowFn:

Details of GroupByKeyAndWindows: Input

Referring back to FIG. 2, the windowing API 300 includes a windowinginterface 320. The windowing interface 320 includes a timestamp setterfunction 322 and a window accessor function 324.

The timestamp setter function 322 updates the timestamp in step contextbefore outputting the element. An example of the timestamp setterfunction 322 may include:

DoFnContext.outputWithTimestamp(O output, long timestamp); {stepContext.getExecutionContext( ).setTimestamp(timestamp);output(output); }

In both batch and streaming modes, it is useful to be able to set ormodify the timestamps of elements in a PCollection (which is arepresentation of an immutable, distributed collection of elements thatis the fundamental target of computation). In batch mode, it is safe toset timestamps arbitrarily; however, in streaming mode, setting atimestamp on an output element that is further in the past than thetimestamp on its corresponding input element can produce late data(e.g., late data point(s)) that will not be properly processed by therest of the pipeline.

There are two caveats to this rule in streaming: first, if a DoFn canprovide a static bound on the amount by which it will shift timestampsbackward, the programmer can hold up the watermark by that amount andstill process the data correctly; second, sometimes producing late datais the desired behavior, and late data can be sensibly handled withtriggers. Therefore, the system 100 provides two proposed APIs withinthe timestamp setter function 322 to handle timestamps shifting backwardin streaming:

Option 1 322 a: ask a user to provide how much the timestamps will beshifted backward.

// Returns the maximum amount by which an output timestamp can be lessthan its corresponding input timestamp long DoFn.lateDataHorizon( )

Option 2 322 b: force users to set OutputTimestampMode ifoutputWithTimestamp is called in streaming.

// By default DoFn.getOutputTimestampMode returns UNBOUNDED_PAST mode,which is not allowed in DoFnContext.outputWithTimestamp for streamingmode. class DoFn { public enum OutputTimestampMode { UNBOUNDED_PAST,BOUNDED_PAST, FURTURE; } public OutputTimestampModegetOutputTimestampMode( ) { return OutputTimestampMode.UNBOUNDED_PAST; }} // Outputs element with the specified timestamp. // This can producelate data DoFnContext.outputWithTimestamp(O output, long timestamp) { if(!outputTimestampModeChecked && options.streaming) {Preconditions.checkArgument ( fn.getOutputTimestampMode( ) !=OutputTimestampMode.UNBOUNDED_PAST); outputTimestampModeChecked = true;} stepContext.getExecutionContext( ).setTimestamp(timestamp);output(output); }

The window accessor function 324 (e.g., DoFn.ProcessContext.windows( ))is one way of accessing windows, but it really only makes sense toaccess them after a GroupByKey, and in that case, each element will onlybe in a single window.

The windowing API 300 uses triggers to handle late data. Withouttriggers, the windowing API 300 uses two possible methods to handle thelate data. The windowing API 300 can drop late data that would not begrouped into the correct window, or the windowing API 300 can allow latedata to create duplicate windows in the output of GroupByKeyAndWindows.The windowing API 300 can either pick one of the options, or allows theoptions to be configurable at either the pipeline level or on Windowtransforms (essentially resulting in a very poor approximation/subset oftriggers).

Eagerness of MergeWindows:

In some examples, it may be difficult to make arbitrary window functionsdeterministic. Instead, the system 100 can quantify exactly when awindow function is deterministic. A WindowingFn will be deterministic ifwhenever a window is ready to be emitted, any windows that it mightmerge with must already be known, and it must merge with all of them.

In some implementation, the system 100 provides batch support throughshuffle. In some examples, the system 100 processes all KVs for a givenkey on the same worker following the logical time order of the element.Then, the worker can leverage the current streaming code, and processthe data as if they are coming from streaming. The system 100 performsthe following to support the batch through shuffle: 1) ShuffleSinkencodes timestamp and windows into ShuffleEntry.value, and use thetimestamp as the keys (sorting key). 2) Create a SortedShuffleSourcereads all KVs for the same key, and return the result with the followinginterface:

Sourcelterator<Reiterable<KV>>iterator(ShuffleEntryReader reader)

long SortedShuffleSourceIterator.ValuesIterator.getTimestamp( );

Collection<BoundedWindow>

SortedShuffleSourceIterator.ValuesIterator.getWindows( );

TODO: reusing code in GroupingShuffleSource.

The following is an exemplary user code that may be executed by thesystem 100:

.apply(TextIO.Read.named(“ReadLines”).from(options.input)).apply(ParDo.named(“ExtractWordsWithTimestampFn”).of(new DoFn<String,String>( ) { @Override public void processElement(ProcessContext c) {String[ ] words = c.element( ).split(“[{circumflex over ( )}a-zA-Z′]+”);for (String word : words) { if (!word.isEmpty( )) {c.outputWithTimestamp(word, System.currentTimeMillis( )); } } }})).apply(Window.into(FixedWindows.<String>of(5, TimeUnit.MILLISECONDS))).apply(ParDo.named(“Count Init”)  .of(new DoFn<String, KV<String,Long>>( ) { @Override public void processElement(ProcessContext c) { c.output(KV.of(c.element( ), 1L)); }})) .apply(GroupByKey.<String,Long>create( )) .apply(ParDo.named(“Count Combine”)  .of(newDoFn<KV<String, Iterable<Long>>, KV<String,  Long>>( ) { @Overridepublic void processElement(ProcessContext c) { KV.of(c.element().getKey( ), getIteratorSize(c.element( ).getValue( ).iterator( )));}})) .apply(ParDo.named(“FormatCounts”)  .of(new DoFn<KV<String, Long>,String>( ) { @Override public void processElement(ProcessContext c) { String output = “Key: ” + c.element( ).getKey( ) + “ Value: ” +c.element( ).getValue( ) + “ Timestamp: ” + c.timestamp( ) + “ (“ +c.windows( ) + ”)”;  c.output(output); }})).apply(TextIO.Write.named(“WriteCounts”).to(options.getOutput( ))

The ability to build unaligned, event-time windows is an improvement,but two more shortcomings need be addressed. First. the system 100 needsto provide support for tuple- and processing-time-based windows,otherwise windowing semantics will regress relative to other systems inexistence. Second, the system 100 must know when to emit the results 20for a window. Since the data 10 including multiple data points areunordered with respect to event time, the system 100 requires some othersignal to notify when the window ends.

The problem of tuple- and processing-time-based windows is addressbelow, after the system 100 builds up a solution to the windowcompleteness problem. As to window completeness, an initial inclinationfor solving it might be to use some sort of global event-time progressmetric, such as watermarks. However, watermarks themselves have twomajor shortcomings with respect to correctness.

The first shortcoming of watermarks is they are sometimes too fast,meaning there may be late data 10 that arrives behind the watermark. Formany distributed data sources, it is intractable to derive a completelyperfect event time watermark, and thus impossible to rely on it solelyif 100% correctness is desired in the results 20 of the output data.

The second shortcoming of watermarks is they are sometimes too slow.Because they are a global progress metric, the watermark can be heldback for the entire pipeline by a single slow datum. And even forhealthy pipelines with little variability in event-time skew, thebaseline level of skew may still be multiple minutes or more, dependingupon the input source. As a result, using watermarks as the sole signalfor emitting window results 20 is likely to yield higher latency ofoverall results than, for example, a comparable Lambda Architecturepipeline.

For these reasons, the system 100 postulates that watermarks alone areinsufficient. A useful insight in addressing the completeness problem isthat the Lambda Architecture effectively sidesteps the issue: it doesnot solve the completeness problem by somehow providing correct answersfaster; it simply provides the best low-latency estimate of a resultthat the streaming pipeline can provide, with the promise of eventualconsistency and correctness once the batch pipeline runs. Output fromthe batch job is only correct if input data 10 is complete by the timethe batch job runs; if data 10 evolves over time, this must be detectedand the batch jobs re-executed. From within a single pipeline(regardless of execution engine), then the system 100 will need afeature to provide multiple answers (or panes) for any given window.This feature includes triggers or trigger times that allow thespecification of when to trigger the output results 20 for a givenwindow.

Triggers are a mechanism for stimulating the production ofGroupByKeyAndWindow results 20 in response to internal or externalsignals. They are complementary to the windowing model, in that theyeach affect system behavior along a different axis of time. Windowingdetermines where in event time data 10 are grouped together forprocessing. Triggering determines when in processing time the results 20of groupings are emitted as panes. Specific triggers, such as watermarktriggers, make use of event time in the functionality they provide, buttheir effects within the pipeline are still realized in the processingtime axis.

In some implementations, the system 100 provides predefined triggerimplementations for triggering at completion estimates (e.g. watermarks,including percentile watermarks, which provide useful semantics fordealing with stragglers in both batch and streaming execution engineswhen processing a minimum percentage of the input data 10 quickly ismore desirable than processing every last piece of it), at points inprocessing time, and in response to data 10 arriving (counts, bytes,data punctuations, pattern matching, etc.). In some examples, the system100 supports composing triggers into logical combinations (and, or,etc.), loops, sequences, and other such constructions. In addition,users may define their own triggers utilizing both the underlyingprimitives of the execution runtime (e.g. watermark timers,processing-time timers, data arrival, composition support) and any otherrelevant external signals (data injection requests, external progressmetrics, RPC completion callbacks, etc.).

In addition to controlling when the system 100 emits results 20, thetriggers API 400 provides a way to control how multiple panes for thesame window relate to each other, via three different refinement modes:

The first refinement mode is discarding: Upon triggering, windowcontents are discarded, and later results 20 bear no relation toprevious results 20. This mode is useful in cases where the downstreamconsumer of the data (either internal or external to the pipeline)expects the values from various trigger fires to be independent (e.g.when injecting into a system that generates a sum of the valuesinjected). It is also the most efficient in terms of amount of data 20buffered, though for associative and commutative operations which can bemodeled as a Dataflow Combiner, the efficiency delta will often beminimal. For the video sessions use case, this is not sufficient, sinceit is impractical to require downstream consumers of the data 10 tostitch together partial sessions.

The second refinement mode is accumulating: Upon triggering, windowcontents are left intact in persistent state, and later results 20become a refinement of previous results 20. This is useful when thedownstream consumer expects to overwrite old values with new ones whenreceiving multiple results 20 for the same window, and is effectivelythe mode used in Lambda Architecture systems, where the streamingpipeline produces low-latency results, which are then overwritten in thefuture by the results 20 from the batch pipeline. For video sessions,this might be sufficient if the system 100 is simply calculatingsessions and then immediately writing them to some output source thatsupports updates (e.g. a database or key/value store).

The third refinement mode is accumulating & retracting: Upon triggering,in addition to the Accumulating semantics, a copy of the emitted valueis also stored in persistent state. When the window triggers again inthe future, a retraction for the previous value will be emitted first,followed by the new value as a normal datum. A simple implementation ofretraction processing requires deterministic operations, butnon-determinism may be supported with additional complexity and cost; wehave seen use cases that require this, such as probabilistic modeling.Retractions are necessary in pipelines with multiple serialGroupByKeyAnd-Window operations, since the multiple results generated bya single window over subsequent trigger fires may end up on separatekeys when grouped downstream. In that case, the second groupingoperation will generate incorrect results 20 for those keys unless it isinformed via a retraction that the effects of the original output shouldbe reversed. Dataflow Combiner operations that are also reversible cansupport retractions efficiently via an uncombine method. For videosessions, this mode is the ideal. If the system 100 is performingaggregations downstream from session creation that depend on propertiesof the sessions themselves, for example, by detecting unpopular ads(such as those which are viewed for less than five seconds in a majorityof sessions), initial results 20 may be invalidated as inputs thatevolve over time, e.g. as a significant number of offline mobile viewerscome back online and upload session data. Retractions provide a way forus to adapt to these types of changes in complex pipelines with multipleserial grouping stages. Some specific implementations of the Triggersystem are discussed below.

The triggers API 400 provides a structured, composable a way ofexpressing when (in processing time) the results 20 of an aggregationshould be emitted within Dataflow/Streaming Flume. The triggers API 400works in conjunction with the aggregation API 200 and the windowing API300, which respectively allow the expression of what the results 20 ofan aggregation are, and where (in event time) the aggregations areperformed. The triggers API 400 aims to address a number of shortcomingsin the existing Streaming Flume/Dataflow APIs relative to standardMillWheel. Some of these shortcomings include:

-   -   Late Data—Streaming Flume users are not able to manage late data        (i.e. data that arrives behind the watermark). Current systems        just drop the late data, which is impractical, even in the        short-term.    -   Speculative Data—Some MillWheel customers perform speculative or        partial aggregations manually using percentile watermarks or        other data-based heuristics, Streaming Flume has zero support        for this currently.    -   Walltime Aggregations—Many MillWheel pipelines do not care about        watermarks, but still want to provide some sort of periodic        windowed aggregation. Walltime timers provide a way to provide        regular updates containing whatever data has been received thus        far, despite how fast or slow the rest of the pipeline may be        operating currently.    -   Data-Driven Aggregations—Another class of aggregations that does        not require watermarks is those driven by the data themselves,        e.g. hash joins or byte-limited aggregations. Many of these        patterns are supported using the existing Streaming Flume APIs        (via custom WindowFns and/or the State API), but it may be        desirable to incorporate them with a generalized aggregation        trigger API, since this would open the possibility of composing        data-driven triggers with other triggers (e.g. a hash join that        times out after a walltime delay; currently you can only use a        streamtime delay).

Watermarks: MillWheel provides watermarks (or cursors) as way ofreasoning about completeness of data in a streaming pipeline. Bydefault, watermarks estimate the point in time up to which all data fora given stream has been received or processed. This allows time-boundaryaggregations to be performed only once the system 100 believes it hasseen all the relevant data.

However, watermarks are established at the point of data injection(i.e., when the data is received), and propagated from there. For manydata sources, it's impossible to provide a watermark that is completelyaccurate. For example, consider log files, a log injector can create awatermark based off of the set of log files the log injector is scanningat any given moment, but if a log saver is delayed for an extendedperiod of time, it is possible for new log files to arrive after theinjector has advanced its watermark. The data in these late log filesare now late. Downstream computations are then left with the burden ofdeciding how to handle the late data. In some cases, it can beincorporated into existing results. In others, it may be best to justdrop the late data. MillWheel provides no structured framework fordealing with late data, just the minimal infrastructure to detect it.Streaming Flume currently provides no method of interacting with latedata; Streaming Flume simply drops it.

Percentile Watermark: MillWheel also supports the notion of percentilewatermarks, which give you a watermark estimating the time up to whichsome specific subset of the data (e.g. 95%) the system 100 hasprocessed. The system 100 may use percentile watermarks instead of thenormal watermark to provide speculative results.

This can be used to provide results faster, with some decreased amountof confidence. However, a given computation can currently only make useof only one type of cursor (100% or a single, cell-specific percentile).So providing a complex, tiered set of speculative results is laboriousfrom a configuration perspective, and currently impossible beyond twotiers.

Walltime Aggregation: While watermarks are the most common way oftriggering aggregations in MillWheel, there are cases where other typesof triggers are more practical. In cases where timeliness of data ismore important that any specific notion of completeness, walltime timersmay be used to provide periodic updates of the data aggregated thus far.This ensures that a programmer gets timely updates, even in the face ofwatermark lags due to a small portion of the data being noticeablybehind the rest.

Data-Driven Aggregation: Moreover, there exists a whole class ofnon-time-based aggregations. Examples are hash-joins, aggregationsbounded by a number of records or bytes, or aggregations triggered onsome feature of the data themselves (e.g. a specific field of a datumhaving a certain value).

Composite Aggregation: In some examples, it is fairly common to want tocompose multiple types of aggregation. Often times, a hash join willhave a timeout. in such example, the current system 100, Streaming Flumewith streamtime timeouts, may be used, but not walltime. In someexamples, the programmer wants to receive a single initial aggregationwhen the watermark reaches 100%, then periodic (based on walltime)updates when late data arrive. Speculative data is essentially anothertype of composite aggregation (one each for the desired percentilewatermark values).

In some examples, the problem of composing aggregations, be it for latedata 10, speculative data, or some other custom composition, then begsthe question: how do you provide refinements to the results of anaggregation as your notion of a dataset changes over time?

Several options may be considered for handling updates to aggregationsin a streaming pipeline. Option 1: Provide multiple versions ofaggregations and ways to manage them. When providing multiple versions,there are two modes the system 100 may support. In a first mode, thesubsequent aggregations incorporate all the data 10 seen thus far. Inthis case, new aggregates 20 would simply replace old aggregates 20. Ina second mode, subsequent aggregations 20 incorporate only new data 10since the last aggregate 20. In this case, new aggregates 20 would haveto be manually combined with previous aggregates 20, if desired and/orfeasible. The first and second options include cleaning services thathave pros and cons. The pros may include, but not limited to: the APIsating clean (different versions of the aggregate still have the sametype); the user specifies their aggregation logic once, and the systemtakes care of applying it multiple times as needed; since the systemalready provides for multiple versions of aggregations (differentiatedby timestamp) with windowing in Streaming Flume, so extending versionsto a new dimension is relatively natural: (1A) updated aggregates 20 areimmediately usable with no extra work from the user; and (1B) no need tokeep aggregation state around for some late data horizon. Cons include(1A) the aggregation state must be kept around until late data is nolonger allowed. For log sources, this would be two days untilgoldenization to be 100% correct. State size depends on the type ofaggregation performed: Combiner: When performing an aggregation withcombineValues, only the intermediate data aggregate (e.g. sum+count foran mean calculation) need be stored.

This yields an overall data storage size of:

O(PARTIAL_AGGREGATE_SIZE*NUM_WINDOWS_IN_HORIZON).

Full-data: Non-combiner aggregations require storing the entire inputdata set up until the time horizon. This yields an overall data storagesize of:

O(INPUT_SIZE_OVER_HORIZON).

(1A) Previous aggregates 20 must be uncombined from any furtherdownstream cumulative aggregations 20. This results in redundant work,and also introduces racy semantics when the new aggregate shuffles to adifferent key than the old aggregate. (1B) The user must do extra workto combine new aggregates with old aggregates.

Another option, option 2, provides an initial aggregation and access theinitial aggregation to raw subsequent data 10 (i.e. “deltas”). Thisoption includes pros such as, but not limited to: the aggregation statedoesn't have to be kept around. As for cons, the API is morecomplicated; aggregate and delta may have different types. Is youroutput from the operation now a Pair<Aggregate, Delta>? Or do yourequire the user to fork their code paths? This kills atomicity; usermust specify their aggregation logic once for the initial aggregate,then a second time for incorporating delta updates. Many types ofaggregations do not support updates via deltas, and thus would not workwith this scheme.

Given the lists of pros and cons, options #1A and #1B are solutions thatthe system 100 may execute for triggering:

Therefore, to address the various use cases described above, the system100 modifies the window the call Window.into to allow users to alsospecify the triggers that dictate when aggregates 20 are emitted, aswell as the way subsequent aggregates 20 relate to previous aggregates20:

windowBy(WindowFn, TriggerStrategy);

Dataflow: Window.into(WindowingStrategy, TriggerStrategy);

The TriggerStrategy object is essentially a tuple of named values:

-   -   1. Trigger—Dictates when aggregates 20 would be emitted, e.g.        first at 100% watermark percentile, then followed by late data        aggregates 20 (when present) every 10 walltime seconds for at        most two days.    -   2. Accumulation mode—Dictates whether later aggregates 20        include data 10 from the previous aggregates 20 or not (i.e.        whether the contents of a window are cleared when the window is        triggered).    -   3. Incremental mode—Dictates whether or not anti-data for        previous aggregates would be emitted to allow for incremental        updates of downstream aggregates.

APIs, High level: the system 100 provides a high-level way to describewhen aggregates 20 should be produced during windowing within aGroupByKey operation, as well as how multiple versions of an aggregate20 relate to each other and whether incremental updates would beperformed, via modified windowBy/Window.into operations:

SF: windowBy(WindowFn, TriggerStrategy)

Dataflow: Window.into(WindowingStrategy, TriggerStrategy) As notedabove, TriggerStrategy is a roughly Tuple<Trigger, AccumlationMode,IncrementalMode>.

A trigger is essentially a DoFn-like class with methods that are calledby the system 100 at specific points during windowing. Those methodstake various arguments about the window(s) and values in question asinput, may manipulate per-window-and-trigger persistent state and times,and may emit trigger signals to indicate when a window's contents shouldbe emitted downstream. More details on the API for implementing Triggersare included below in the implementation section.

As with the Windowing APIs 400, custom Trigger implementations arerelatively rare. From an end-user perspective, the more interesting partis really the library of pre-built Triggers that we provide.

The triggers library contains both simple and composite triggers (thoughthe distinction between them is largely semantic). Example simpletriggers include:

-   -   WatermarkPercentile(float percentile)—Emit an aggregate when the        given watermark percentile is reached for the end of the window,        with percentile in (0.0, 100.0]. Under the covers, these would        be implemented via watermark timers. Note that late windows        would by definition not fire this type of Trigger.        AtPeriod(DateTime reference, long period, TimeUnit units,        TimeDomain domain)    -   Emit an aggregate for the window at the end of the next time        window that aligns with the given reference time (reference may        be any valid DateTime) using the given period. When run        repeatedly, allows periodic aggregates to be emitted, e.g. every        period seconds. TimeDomain can be STREAM_TIME or WALL_TIME.

Under the covers, these would be implemented via watermark or walltimetimers. AfterDelay(long delay, TimeUnit units, TimeDomain domain)—Emitan aggregate some amount of time after the first datum in the window isseen, e.g. after delay seconds. TimeDomain can be STREAM_TIME orWALL_TIME. Under the covers, these would be implemented via watermark orwalltime timers.

-   -   AfterBytes(long count)—Emit an aggregate after count number of        bytes have been seen.    -   AfterCount(long recordCount)—Emit an aggregate after count        number of records have been seen    -   Custom Trigger—Call a user-provided implementation of the        Trigger interface for every record.        -   /**        -   *Called to decide if an aggregate should be emitted after        -   *this datum is incorporated into the aggregate.        -   *@param elem The datum.        -   *@param state Trigger-specific state.        -   *@return Pair indicating whether an aggregate should be            emitted,        -   *and what the new state for the trigger is.        -   */        -   interface UserTrigger<DATA, STATE>extends Trigger {        -   Pair<boolean, STATE>shouldEmit(DATA elem, STATE state);        -   }

The AfterBytes and AfterCount triggers above could be implemented usingthis API. So could Z3's Speculative Differs. This provides essentiallythe same semantics as a custom WindowFn.merge call that callsWindowSet.emit to emit windows early.

Example composite triggers include:

-   -   FirstOf(Trigger . . . triggers)—At most one of the provided        triggers will be allowed to fire.    -   SequenceOf(Trigger . . . triggers)—The specified triggers will        be allowed to fire in order.    -   Repeat(Trigger trigger)—After firing, the specified trigger will        reset and be allowed to fire again, forever.    -   RepeatUntil(Trigger trigger, Trigger until)—Same as repeat,        except the repetition ends when the until Trigger fires.    -   RepeatCount(Trigger trigger, int count)—Same as Repeat, except        until the trigger has fired count times.

Given these primitives, you can express a number of useful aggregationpatterns. For example:

-   -   Emit 90% and 100% watermark percentile aggregates, followed by        late data aggregates every walltime hour on the hour (when they        exist) until two days of data have been processed:        -   new SequenceOf(        -   new WatermarkPercentile(0.9),        -   new WatermarkPercentile(1.0),        -   new RepeatUntil(        -   new AtPeriod(DateTime.now( ).toDateMidnight( ),            -   1, TimeUnit.HOURS, TimeDomain.WALL_TIME), new                AfterDelay(2, TimeUnit.DAYS, TimeDomain.STREAM_TIME));                Perform repeated hash joins, each with one-hour walltime                timeout. This would probably be used with the                GlobalWindowFn/GlobalWindow, but would not have to be:        -   new Repeat(        -   new FirstOf(        -   new HashJoinTrigger( ), //Implements hash join logic as a            Trigger.        -   new AfterDelay(1, TimeUnit.HOURS, TimeDomain.WALL_TIME)));    -   Emit a global aggregation (e.g. a global count of records seen        over all time) daily at 8 am. This use case is one of the        motivations for the Streaming Flume timer API. Given windowing        triggers, the timer API can deprecate (and we don't currently        expose it for Dataflow).    -   new Repeat(    -   new AtPeriod(new DateTime(2000, 1, 1, 8, 0),        -   1, TimeUnit.DAYS, TimeDomain.WALL_TIME));

The AccumulationMode enum may have four possible values:

-   -   CLEAR_ALWAYS—Never accumulate values across trigger calls,        ignoring explicit accumulate requests from trigger        implementations.    -   CLEAR_BY_DEFAULT—Clear unless accumulation is explicitly        requested by a trigger implementation.    -   ACCUMULATE_BY_DEFAULT—Accumulate unless clearing is explicitly        requested by a trigger implementation.    -   ACCUMULATE_ALWAYS—Always accumulate values across trigger calls,        ignoring explicit clear requests from trigger implementations.

IncrementalMode supports values ENABLED or DISABLED. If enabled, thesystem would support reversing the effects of previous aggregate valuesin downstream aggregations via anti-data (e.g. data that are flagged asbeing used to reverse effects from previously emitted aggregates). Thisfeature is complex enough it warrants its own design doc, and not beincluded in any of the initial Dataflow or Flume implementations.

The combination of AccumulationMode.ALWAYS and IncrementalMode=truewould effectively be Option 1A above. While the combination ofAccumulationMode.NEVER and IncrementalMode=false would effectively beOption 1B above (the default mode for the system).

When eventually grouped by key, the results of the GroupByKey mayinclude multiple versions of any given aggregate. These versions wouldbe distinguishable by their production time values, as well as theassociated trigger that generated them (as described further in theLow-level API section below).

The one-parameter version of windowBy would be deprecated in an attemptto force the user to explicitly think about when it's appropriate fortheir aggregations to be emitted. While it remained, it would beimplemented in such a way as to provide the original semantics ofemitting only at the 100% watermark, with all subsequent late datadropped, e.g.:

windowBy(WindowFn, new TriggerStrategy(

-   -   new SequenceOf(new WatermarkPercentile(100)),    -   AccumulationMode.NEVER,    -   IncrementalMode.DISABLED));

Processing Context API: The standard ExecutionContext/ProcessingContextclasses may gain some new methods to provide low-level, per-valuemetrics to reason about multiple versions of aggregates.

-   -   Integer ExecutionContext.getWatermarkPercentile( )—Provides the        watermark percentile for any value in the system. This will be        an integer in [0, 100], or null if the value was produced behind        the 100% output watermark (i.e. the value is late). By        definition, the watermark percentile will be the fraction of        tablets/ranges with watermark values >=the event time of the        given value at production time. For internal MillWheel, this        would be done via a set of pre-defined percentile watermarks.        For Cloud MillWheel, if we provide watermark histograms, we        could derive this from the histogram.    -   long ExecutionContext.getProductionTime( )—Returns the        production time for the value. Can be used to distinguish        multiple versions of an aggregate chronologically.    -   Trigger ExecutionContext.getTrigger( )—Provides the Trigger (if        any) that generated this value. For non-aggregate values,        returns null. Inspecting this value would allow you to        determine, for example, if a datum was late or not.    -   boolean ExecutionContext.isAntiDatum( )—True if the datum is an        anti-aggregate (or something derived from an anti-aggregate).        Used for uncombining previous aggregates in a pipeline with        multiple aggregation stages running with        AccumulationMode.Cumulative.

When eventually grouped by key, this would yield at least two version ofevery window: one for the 95th-percentile of data, and one for the100th-percentile of data. If any late data arrived, you would also getan updated version of the aggregation for each late datum.

Implementation of the Flume triggers API: Simple triggers areimplemented via subclasses of the Trigger<B extends Window, T>class. Theclass consists of three abstract methods that are called into by thewindowing API 400 each of which receives a specialized context classthat provides all the operations available in the given context.

-   -   onDatum—Called immediately after a datum is first incorporated        into a window. Provided with both the window and the        (unincorporated) value. The full aggregate value of the window        may be accessed via Window.peekValue( ) which may be expensive        if not using an AggrFn. May read/write per-tag state for the        window.

May inspect the current time in all time domains. May set/delete per-tagtimers for the window. May trigger and clear the window value. May markthe Trigger done.

void onDatum(OnDatumContext ctx); class OnDatumContext { B window( ); Tdatum( ); <V> V lookupState(String tag, Coder<V> coder); <V> voidstoreState(String tag, V value, Coder<V> coder); Instant now(TimeDomaindomain); Timer getTimer(String tag); void setTimer(String tag, Instanttime, TimeDomain domain); void deleteTimer(String tag); void trigger( );// shorthand for trigger(Mode.DEFAULT); void trigger(Mode mode); voiddone( ); } enum Mode { ACCUMULATE, DEFAULT, CLEAR; }

-   -   onMerge—Called immediately after window merging has occurred.        Provided with the source windows and the merged window. May read        per-tag state for source windows, and write per-tag state for        the merged window. May inspect the current time in all time        domains. May inspect per-tag timers for source windows and set        per-tag timers for the merged window. May trigger and clear the        window value. May mark the Trigger done. All state and unfired        timers for source windowswill be deleted (via calls to reset)        upon callback completion.

void onMerge(OnMergeContext ctx); class OnMergeContext { Iterable<B>sourceWindows( ); B mergedWindow( ); <V> V lookupSourceState( B window,String tag, Coder<V> coder); <V> void storeState( String tag, V value,Coder<V> coder); Instant now(TimeDomain domain); void getSourceTimer(Bwindow, String tag); void setTimer( String tag, Instant time, TimeDomaindomain); void trigger( ); // shorthand for trigger(Mode.DEFAULT); voidtrigger(Mode mode); void clear( ); void done( ); }

-   -   onTimer—Called when a timer set by the trigger fires. Provided        with the window and the timer tag, instant, and domain. May        read/write per-tag state and for the window. May inspect the        current time in all time domains. May set/delete per-tag timers        for the window. May trigger and clear the window value. May mark        the trigger done.

void onTimer(OnTimerContext ctx); class OnTimerContext { B window( );String tag( ); Instant time( ); TimeDomain domain( ); <V> VlookupState(String tag, Coder<V> coder); <V> void storeState(String tag,V value, Coder<V> coder); Instant now(TimeDomain domain); voidgetTimer(String tag); void setTimer(String tag, Instant time, TimeDomaindomain); void deleteTimer(String tag); void trigger( ); // shorthand fortrigger(Mode.DEFAULT); void trigger(Mode mode); void clear( ); voiddone( ); } }

Note that, for the sake of allowing helper methods to be written andused from multiple different callbacks when performing compatibleoperations, common context methods (such as lookupState) is defined inits own interface, e.g.:

interface LookupStateContext { <V> V lookupState(String tag, Coder<V>coder); }

Note the promotion of timers to a first-class object. This requires thatthe system 100 track all timers in persistent state under the covers,but relieves the user of the burden of doing so (which is a common useof persistent state when dealing with timers), and allows the system 100to clean up all timers for a trigger automatically during garbagecollection.

interface Timer { String tag( ); Instant time( ); TimeDomain domain( );}

Integration into the existing windowing system is relativelystraightforward, with the two main invocation points being after a datumis first incorporated into a window (for onDatum) and after windowshavebeen merged by the WindowingStrategy's merge function (for onMerge).

More interesting is how to support the creation of composite triggers,e.g. FirstOf, SequenceOf, etc. Composite triggers would be implementedusing the CompositeTrigger class, which provides a superset of thefunctionality of Trigger (and indeed is an actual superclass of it).Each context in CompositeTrigger would support one or two additionaloperations:

-   -   invokeChild—Invokes the current callback on the given child        trigger. Available in all operations (onDatum, onMerge, onTimer,        reset). Under the covers, keeps track of the lineage up to the        current child, using that lineage to provide unique namespaces        for all state and timers manipulated by any given child. Also        allows void invokeChild(Trigger trigger);    -   triggerHistory—Return the sequence of child triggers within        which the ctx.trigger( )method has been invoked during the        lifetime of this callback as a list of TriggerEvent objects        (which capture the invoking trigger and whether a clear was        requested). Available in all operations whose context class        includes a trigger method (onDatum, onMerge, onTimer). Note that        the triggers returned by triggerHistory are strictly among the        direct descendents of this specific trigger (e.g. grandchild        triggers will never directly show up in the results of this        function call, though they may result in a child trigger showing        up).

interface TriggerEvent { Trigger trigger( ); bool andClear( ); } classTriggerHistory implements Iterable<TriggerEvent> { long size( ); boolallClear( ); } TriggerHistory triggerHistory( );

In addition, CompositeTrigger provides a fourth callback that allows aparent to hook into a child's timer callback, since timers are scoped toa specific trigger, but may have implications for a parent:

-   -   onChildTimer—Called when a timer set by a child trigger fires.        Provided with the window, the child trigger, and the timer tag,        instant, and domain. May read/write its own per-tag state and        for the window. May inspect the current time in all time        domains. May inspect/set/delete its own per-tag timers for the        window. May trigger and clear the window value. May mark the        trigger done. May invoke the child timer. May inspect any        trigger calls made by the child.

void onChildTimer(OnTimerContext ctx); class OnTimerContext { B window (); String tag( ); Trigger child( ); Instant time( ); TimeDomain domain(); <V> V lookupState(String tag, Coder<V> coder); <V> voidstoreState(String tag, V value, Coder<V> coder); Instant now(TimeDomaindomain); Timer getTimer(String tag); void setTimer(String tag, Instanttime, TimeDomain domain); void deleteTimer(String tag); void trigger( );// shorthand for trigger(Mode.DEFAULT); void trigger(Mode mode); voiddone( ); void invokeChild( ); TriggerHistory triggerHistory( ); }

By using these APIs, it is possible for the system 100 to provide thecomplete expressiveness of the MillWheel API, while typically notrequiring end users to deal with the complexities of the underlyinglow-level API. For a suite of example Trigger implementations, seebelow.

On-disk state: Triggers store the following on-disk state.

-   -   User tag/value pairs.    -   User timers (in the timer system)    -   User tag/Timer pairs (in persistent state)    -   A snapshot of the last emitted value for the window if        Incremental Mode is enabled.    -   A tombstone for Triggers that are marked done.

Accumulation Mode:

The system 100 may follow the directions of the accumulation modesetting for the current TriggerStrategy when deciding whether toautomatically clear the window value on trigger calls and whether toobey clear calls from the Trigger implementations.

Incremental Mode: Anti-data consisting of the previous value for awindow would be generated any time a window is triggered.

When windows are merged in incremental mode, their last-emitted values(if any) are merged as well. Downstream, all non-GroupByKey operationson an anti-datum produce more anti-data (similar to timestamppropagation). When a GroupByKey operation is reached, anti-data are fedinto the uncombine method. The result of an uncombine is then normaldata, not anti-data; however, if the TriggerStrategy for that GBKenables Incremental Mode, then an anti-datum for the previous value ofthat window will also be emitted. The system 100 is not targetingIncremental Mode support initially for any of the Dataflow/Flumeproducts; the feature probably merits a design doc all of its own.

MillWheel: MillWheel may support extra metadata via annotations (e.g.,similar to as for windows):

-   -   Trigger metadata will be added when a trigger fires.    -   Watermark percentiles will be annotated on raw data at        injectors, and on aggregate data at trigger time.    -   Anti-data are tagged as such when emitted.

Providing fine-grained estimates of watermark percentiles will requiretracking global watermark histograms instead of single minimum watermarkvalues. Watermark histograms are planned for WindMill. They would needto be added to MillWheel.

Two features in this API would require support for multiple timermanagers:

-   -   Arbitrary watermark percentile triggers.    -   TriggerSets containing both watermark and walltime timers.

WindMill is built with support for multiple timer managers, and shouldbe able to support the watermark+walltime feature out of the box.Support for multiple watermark percentiles shouldn't be too much moredifficult. MillWheel may need a refactoring of the timer manager code tosupport either feature.

Appendix A—Example Trigger Implementations

AfterCount

class AfterCount<B, T>extends Trigger<B, T>{

private final long threshold;

public AfterCount(long threshold) { this.threshold = threshold; }@Override public void onDatum(OnDatumContext ctx) { Long count =ctx.lookupState(“count”, LONG_CODER); if (count == null) count = 0;storeAndPossiblyEmit(count + 1); } @Override public voidonMerge(OnMergeContext ctx) { int mergedCount = 0; for (B window :ctx.sourceWindows( )) { Long count = ctx.lookupSourceState(window,“count”, LONG_CODER); if (count != null) mergedCount += count; }storeAndPossiblyEmit(mergedCount, count); } @Override protected voidreset(ResetContext ctx) { clearState(“count”); } private voidstoreAndPossiblyEmit( StoreStateContext stateCtx, TriggerContexttriggerCtx, long count) { if (count > threshold) { triggerCtx.trigger(); triggerCtx.done( ); } else { stateCtx.storeState(“count”, count,LONG_CODER); } } AfterDelay class AfterDelay<B, T> extends Trigger<B, T>{ private final delay; private final TimeDomain domain; publicAfterDelay(long delay, TimeDomain domain) { assert delay >= 0;this.delay = delay; this.domain = domain; } @Override public voidonDatum(OnDatumContext ctx) { if (getTimer(“delay”) == null)setTimer(“delay”, ctx.now(domain) + delay, domain); } @Overrideprotected void onMerge(OnMergeContext ctx) { long maxTime = −1; for (Bwindow : ctx.sourceWindows( )) { Timer timer = getSourceTimer(window,“delay”); if (timer) maxTime = Math.max(timer.time( ).toLong( ),maxTime); } if (maxTime >= 0) setTimer(“delay”, ctx.now(domain) + delay,domain); } @Override public void onTimer(OnTimerContext ctx) {ctx.trigger( ); ctx.done( ); } } AtWatermark class AtWatermark<B, T>extends Trigger<B, T> { public AtWatermark(double percentile) { assertpercentile == 100.0; this.percentile = percentile; } @Override protectedvoid onDatum(OnDatumContext ctx) { B window = ctx. window( ); if(window.end( ) <= ctx.now(TimeDomain.STREAM) &&ctx.getTimer(“watermark”) == null) { ctx.setTimer(“watermark”,window.end( ), TimeDomain.STREAM); } } @Override protected voidonTimer(OnTimerContext ctx) { ctx.trigger( ); ctx.done( ); } @Overrideprotected void onMerge(OnMergeContext ctx) { ctx.setTimer(“watermark”,ctx.mergedWindow( ).end( ), TimeDomain.STREAM); } } ResultIdOdd classResultIsOdd<B, T extends Long> extends Trigger<B, T> { publicResultIsOdd( ) { } @Override public void onDatum(OnDatumContext ctx) {handleWindowed(ctx. window( )); } @Override public void onMerge(Bwindow1, B window2, B windowMerged) { handleWindow(ctx.mergedWindow( ));} private handleBucket(B window, TriggerContext ctx) { Long result =window.peekValue( ); if (result % 2 = 1) ctx.trigger( ); } } FirstOfclass FirstOf extends CompositeTrigger { private final TriggerFn[ ]triggers; public FirstOf(TriggerFn... triggers) { this.triggers =triggers; } @Override private void onDatum(OnDatumContext ctx) { for(Trigger trigger : triggers) { trigger.invokeChild(trigger); }maybeTrigger(ctx); } @Override private void onMerge(B window1, Bwindow2, B windowMerged) { for (Trigger trigger : triggers) {ctx.invokeChild(trigger); if (ctx.triggerHistory( ).size( ) > 0) break;} maybeTrigger(ctx); } @Override public onChildTimer(OnChildTimerContextctx) { invokeChild( ); maybeTrigger(ctx); } private voidmaybeTrigger(CompositeTriggerContext ctx) { TriggerHistory history =ctx.triggerHistory( ); if (history.size( ) > 0) {ctx.trigger(history.iterator( ).next( ).andClear( )); ctx.done( ); } }SequenceOf class SequenceOf<B, D> extends CompositeTrigger<B, D> {private final TriggerFn[ ] triggers; public SequenceOf(TriggerFn...triggers) { this.triggers = triggers; } @Override private voidonDatum(OnDatumContext ctx) { invokeChild(activeTrigger(window));maybeTriggerAndIncrement(ctx, ctx); } @Override publiconChildTimer(OnChildTimerContext ctx) { assertactiveTrigger(ctx).equals(ctx.trigger( )); invokeChild( );maybeTriggerAndIncrement(ctx, ctx); } @Override private voidonMerge(OnMergeContext ctx) { int minIndex = triggers.length; for (Bwindow: ctx.sourceWindows( )) { int index =lookupIndex(ctx.asLookupStateContext(window)); minIndex =Math.min(minIndex, index); } assert minIndex != triggers.length; //Starting at the min index of all sequences being // merged, merge andlook for triggers until you get // to an index that doesn't trigger orrun out of // indices. invokeChild for merges is smart enough // to nottry to merge triggers that are already // done (and to not call merge ifonly one non-done // child trigger exists) TriggerHistory history =ctx.triggerHistory( ); int lastTriggerHistorySize = 0; int index =minIndex; for (; i < triggers.length; ++i) { invokeChild(triggers[i]);if (history.size( ) == lastTriggerHistorySize) break;lastTriggerHistorySize = history.size( ); ctx.trigger(history.allClear()); } storeOrMarkDone(ctx, index); } private voidstoreOrMarkDone(StateAndTriggerContext ctx, int index) { if (index ==triggers.length( )) { ctx.done( ); } else { ctx.storeState(“index”,index, INT_CODER); } } private voidmaybeTriggerAndIncrement(StateAndTriggerContext ctx) { TriggerHistoryhistory = ctx.triggerHistory( ); if (history.size( ) > 0) {ctx.trigger(history.allClear( )); storeOrMarkDone(ctx,lookupIndex(ctx) + 1); } } private int lookupIndex(LookupStateContextctx) { Integer index = ctx.lookupState(“index”, INT_CODER); if (index ==null) index = 0; return index; } private TriggeractiveTrigger(LookupStateContext ctx) { returntriggers[lookupIndex(ctx)]; } }

FIGS. 6A-6I show example plots 600, 600 a-i that highlight a pluralityof useful output patterns supported by the system 100. The example plot600 is illustrated in the context of the integer summation pipeline.

PCollection<KV<String, Integer>>output=input

.apply(Sum.integersPerKey( ));

Using an input source from which the system 100 receives data 10including ten data points, each data point associated with a smallinteger value and analyzed by the system 100 in the context of bothbounded and unbounded data sources. For diagrammatic simplicity, thesystem 100 in the example plots 600 assumes the data points of thereceived data 10 are for the same key; however, in a real pipeline, theoperations performed by the system 100 would be happening in parallelfor multiple keys. FIG. 6A is an example plot 600 showing a window timedomain skew for the data point inputs of the received data 10. The Xaxis plots the data 10 in event time (i.e. when the events actuallyoccurred), while the Y axis plots the data 10 in processing time (i.e.when the pipeline observes them). All the plots 600, 600 a-i assumeexecution on the streaming engine unless otherwise specified.

Many of the plots 600 will also depend on watermarks when included inthe plots 600. In these scenarios, the plots 600 show an ideal watermarkand an example actual watermark. The straight dotted line with slope ofone rep-resents the ideal watermark, i.e. if there were no event-timeskew and all events were processed by the system 100 as they occurred.Given the vagaries of distributed systems, skew is a common occurrence;this is exemplified by the meandering path the actual watermark takesfrom the ideal watermark, as shown in the plot 600 a of FIG. 6A. Notealso that the heuristic nature of this watermark is exemplified by thesingle “late” datum (e.g., data point) with value 9 that appears behindthe watermark.

If the system 100 were to process the received data 10 in a classicbatch system using the described summation pipeline, the system 100would wait for all the data 10 to arrive, group the data 10 togetherinto one bundle (since these data points are all for the same key), andsum their values to arrive at a total result of 51. The plot 600 b ofFIG. 6B shows this result represented by the darkened rectangle, whereatthe area covers the ranges of event time and processing time included inthe sum (with the top of the rectangle denoting when in processing timethe result was materialized). Since classic batch processing isevent-time agnostic, the result 20 is contained within a single globalwindow covering all of event time. And since outputs are only calculatedonce all inputs (e.g., data 10) are received, the result 20 covers allof processing time for the execution.

Note the inclusion of watermarks in plot 600 b. Though not typicallyused for classic batch processing, watermarks would semantically be heldat the beginning of time until all data 10 has been processed, thenadvanced to infinity. An important point to note is that one can getidentical semantics to classic batch by running the data through astreaming system with watermarks progressed in this manner.

In some implementations, the system converts the pipeline to run over anunbounded data source. In Dataflow, the default triggering semantics areto emit windows when the watermark passes them. But when using theglobal window with an unbounded input source, the triggering semanticswill not emit windows when the watermark passes since the global windowcovers all of event time. As such, the system 100 needs to eithertrigger by something other than the default trigger, or window bysomething other than the global window. Otherwise, the system 100 willnot produce an output result 20.

In some examples, changing the trigger allows the system 100 to generateconceptually identical outputs (a global per-key sum over all time), butwith periodic updates. In these examples, the system 100 applies aWindow.trigger operation that repeatedly fires on one-minute periodicprocessing-time boundaries. The system 100 may specify the Accumulatingmode so that the global sum will be refined over time (this assumes thesystem 100 includes an output sink into which the system 100 mayoverwrite previous results for the key with new results, e.g. a databaseor key/value store). Referring to plot 600 c of FIG. 6C, the system 100generates updated global sums once per minute of processing time. Notehow the semi-transparent output rectangles (e.g., windows) overlap,since Accumulating panes build upon prior results by incorporatingoverlapping regions of processing time:

PCollection<KV<String, Integer>>output=input

.apply(Window.trigger(Repeat(AtPeriod(1, MINUTE)))

-   -   .accumulating( ))    -   .apply(Sum.integersPerKey( ));

Conversely, the plot 600 d of FIG. 6D shows the system 100 generatingthe delta in sums once per minute by switching to the Discarding mode.Note that by switching to the Discarding mode, the system 100effectively gives the processing-time windowing semantics provided bymany streaming systems. The output panes no longer overlap, since theirresults incorporate data from independent regions of processing time.

PCollection<KV<String, Integer>>output=input

.apply(Window.trigger(Repeat(AtPeriod(1, MINUTE)))

-   -   .discarding( ))    -   .apply(Sum.integersPerKey( ));

Another more robust way of providing processing-time windowing semanticsis to simply assign arrival time as event times at data ingress, thenuse event time windowing. A nice side effect of using arrival time eventtimes is that the system has perfect knowledge of the event times inflight, and thus can provide perfect (i.e. non-heuristic) watermarks,with no late data. This is an effective and cost-efficient way ofprocessing unbounded data for use cases where true event times are notnecessary or available.

Before incorporating other windowing options, the system 100 mayconsider one more changes to the triggers for this pipeline. In someexamples, the system 100 may model tuple-based windows by simplychanging the trigger to fire after a certain number of data arrive, saytwo. Referring to FIG. 6E, the plot 600 e shows five output results fromindependent regions of processing time. For instance, each outputresults contains the sum of two adjacent (by processing time) data pointinputs. More sophisticated tuple-based windowing schemes (e.g. slidingtuple-based windows) require custom windowing strategies, but areotherwise supported.

PCollection<KV<String, Integer>>output=input

-   -   .apply(Window.trigger(Repeat(AtCount(2)))        -   .discarding( ))    -   .apply(Sum.integersPerKey( ));

Other examples for supporting un-bounded sources include switching awayfrom global windowing. Here, the system 100 may window (e.g., via theWindowing API 300) the data 10 into fixed, two-minute Accumulatingwindows:

PCollection<KV<String, Integer>>output=input

-   -   .apply(Window.into(FixedWindows.of(2, MINUTES)        -   .accumulating( )    -   .apply(Sum.integersPerKey( );

With no trigger strategy specified, the system 100 would use the defaulttrigger, which is effectively:

PCollection<KV<String, Integer>>output=input

-   -   .apply(Window.into(FixedWindows.of(2, MINUTES))        -   .trigger(Repeat(AtWatermark( )))        -   .accumulating( ))    -   .apply(Sum.integersPerKey( ));

The watermark trigger fires when the watermark passes the end of thewindow in question. Both batch and streaming engines implementwatermarks, as detailed below. The Repeat call in the trigger is used tohandle late data; should any data arrive after the watermark, they willinstantiate the repeated watermark trigger, which will fire immediatelysince the watermark has already passed.

Referring to FIGS. 6F-6H, the plots 600 f-600 h each characterize thispipeline on a different type of runtime engine. In some implementations,the system 100 first observes what execution of this pipeline would looklike on a batch engine. In these implementations, the data source wouldhave to be a bounded one, so as with the classic batch example above,the system 100 would wait for all data 10 in the batch to arrive.Thereafter, the system 100 would then process the data in event-timeorder by emitting windows as the simulated watermark advances, as in theexample plot 600 f of FIG. 6F.

When executing a micro-batch engine over this data source with oneminute micro-batches, the system 100 would gather input data 10 for oneminute, process the data 10, and repeat. Each time, the watermark forthe current batch would start at the beginning of time and advance tothe end of time (technically jumping from the end time of the batch tothe end of time instantaneously, since no data would exist for thatperiod). The system 100 ends up with a new watermark for everymicro-batch round, and corresponding outputs for all windows whosecontents had changed since the last round. This provides a very nice mixof latency and eventual correctness, as in the example plot 600 g ofFIG. 6G.

When executing the pipeline in a streaming engine, the plot 600 h ofFIG. 6H shows a late data point updating an output result of a fixedwindow. While most windows emit their associated data points when thewater mark passes, the system 100 receives datum (e.g., data point) withvalue 9 late relative to the watermark. For whatever reason (mobileinput source being offline, network partition, etc.), the system 100 didnot realize that the datum with value 9 had not yet been injected, andthus, having observed the datum with value 5 associated with the samewindow (for event-time range [12:00, 12:02]), allowed the watermark toproceed past the point in event time that would eventually be occupiedby the datum with value 9. Hence, once the datum with value 9 finallyarrives, it causes the first window (for event-time range [12:00,12:02]) to retrigger with an updated sum.

This output pattern is nice in that we have roughly one output perwindow, with a single refinement in the case of the late datum. But theoverall latency of results is noticeably worse than the micro-batchsystem, on account of having to wait for the watermark to advance; thisis the case of watermarks being too slow.

If the system 100 desires lower latency via multiple partial results forall of our windows, the system 100 may add in some additional,processing-time-based triggers to provide regular updates until thewatermark actually passes. Referring to FIG. 6I, plot 600 i shows outputresults based on processing-time-based triggers to yield somewhat betterlatency than the micro-batch pipeline of plot 600 h, since the datapoints of the received data accumulatein windows as they arrive insteadof being processed in small batches. Given strongly-consistentmicro-batch and streaming engines, the choice between them (as well asthe choice of micro-batch size) really becomes just a matter of latencyversus cost, which is exactly one of the goals the system 100 mayachieve based on the following model.

PCollection<KV<String, Integer>>output=input

-   -   .apply(Window.into(FixedWindows.of(2, MINUTES))    -   .trigger(SequenceOf(    -   RepeatUntil(    -   AtPeriod(1, MINUTE),    -   AtWatermark( )),    -   Repeat(AtWatermark( )))    -   .accumulating( ))    -   .apply(Sum.integersPerKey( ));

Referring to FIG. 6J, the plot 600 j shows the data points of thereceived data 10 grouped within session windows and combined outputresults emitted from combined window sessions. Here, the system 100 maysatisfy the video sessions requirements (modulo the use of summation asthe aggregation operation, maintained for diagrammatic consistency;switching to another aggregation would be trivial), by updating tosession windowing with a one minute timeout and enabling retractions.This highlights the composability provided by breaking the model intofour pieces (what the system 100 is computing, where the system 100 iscomputing in event time, when in processing time the system 100 emitsresults of the computing, and how those results relate to laterrefinements), and also illustrates the power of reverting previousvalues which otherwise might be left uncorrelated to the value offeredas replacement.

PCollection<KV<String, Integer>>output=input

.apply(Window.into(Sessions.withGapDuration(1,

-   -   MINUTE)).trigger(SequenceOf(RepeatUntil(        -   AtPeriod(1, MINUTE),        -   AtWatermark( )),        -   Repeat(AtWatermark( )))    -   .accumulatingAndRetracting( ))    -   .apply(Sum.integersPerKey( ));

In the example plot 600 j of FIG. 6J, the system 100 outputs initialsingleton sessions for values 5 and 7 at the first one-minuteprocessing-time boundary. At the second minute boundary, the system 100outputs a third session with value 10, built up from the values 3, 4,and 3. When the value of 8 is finally observed, it joins the twosessions with values 7 and 10. As the watermark passes the end of thisnew combined session, the system 100 emits retractions for the values 7and 10 sessions, as well as a normal datum for the new session withvalue 25. Similarly, when the datum with value 9 arrives (late), itjoins the session with value 5 to the session with value 25. Therepeated watermark trigger then immediately emits retractions for bothvalue 5 and value 25, followed by a combined session of value 39. Asimilar execution occurs for the data points with values 3, 8, and 1,ultimately ending with a retraction for an initial value 3 session,followed by a combined session value 12.

FlumeJava may implement the system 100, with MillWheel used as theunderlying execution engine for streaming mode; additionally, anexternal reimplementation for Cloud Dataflow is largely complete at thetime of writing. Due to prior characterization of those internal systemsin the literature, as well as Cloud Dataflow being publicly available,details of the implementations themselves are elided here for the sakeof brevity. One interesting note is that the core windowing andtriggering code is quite general, and a significant portion of it isshared across batch and streaming implementations; that system itself isworthy of a more detailed analysis in future work.

Important factors for design from real world experience are below. Fordesigning the Dataflow Model, real-world experiences with FlumeJava andMill-Wheel over the years are considered. Configurations which workedwell, may be incorporated, while configurations with less desirableresults motivated changes in the Dataflow Model design.

A number of teams run log joining pipelines on MillWheel. Oneparticularly large log join pipeline runs in streaming mode on MillWheelby default, but has a separate Flume-Java batch implementation used forlarge scale backfills. A much nicer setup would be to have a singleimplementation written in a unified model that could run in bothstreaming and batch mode without modification. This became the initialmotivating use case for unification across batch, micro-batch, andstreaming engines, and was highlighted in plots 600 f-600 h of FIGS.6F-6H.

Another motivation for the unified model came from an experience withthe Lambda Architecture. Though most data processing use cases arehandled exclusively by a batch or streaming system, one MillWheelcustomer ran their streaming pipeline in weak consistency mode, with anightly MapReduce to generate truth. They found that customers stoppedtrusting the weakly consistent results over time, and as a resultreimplemented their system around strong consistency so they couldprovide reliable, low latency results. This experience further motivatedthe desire to support fluid choice amongst execution engines.

From the outset, the system 100 needed to support sessions; this in factis the main contribution of the underlying windowing model over existingmodels. Sessions are an extremely important use case (and were in factone of the reasons MillWheel was created), and are used across a numberof product areas, including search, ads, analytics, social, and YouTube.Any product that correlates bursts of otherwise disjoint user activityover a period of time does so by calculating sessions. Thus, support forsessions became paramount in the design of the Dataflow Modelimplemented by system 100. As shown in the plot 600 j of FIG. 6J, thesystem 100 generating sessions in the Dataflow Model is trivial.

Two teams with billing pipelines built on MillWheel experienced issuesthat motivated parts of the model. Recommended practice at the time wasto use the watermark as a completion metric, with ad hoc logic to dealwith late data or changes in source data. Lacking a principled systemfor updates and retractions, a team that processed resource utilizationstatistics ended up leaving our platform to build a custom solution (themodel for which ended being quite similar to the one we developedconcurrently). Another billing team had significant issues withwatermark lags caused by stragglers in their input. These shortcomingsbecame major motivators in our design, and influenced the shift of focusfrom one of targeting completeness to one of adaptability over time. Theresults were twofold: triggers, which allow the concise and flexiblespecification of when results are materialized, as evidenced by thevariety of output patterns possible over the same data set in plots 600c-600 j FIGS. 6C-6J; and incremental processing support via accumulation(FIGS. 6C and 6D) and retractions (FIG. 6J).

Many MillWheel pipelines calculate aggregate statistics (e.g. latencyaverages). For them, 100% accuracy is not required, but having a largelycomplete view of their data in a reasonable amount of time is. Given thehigh level of accuracy we achieve with watermarks for structured inputsources like log files, such customers find watermarks very effective intriggering a single, highly-accurate aggregate per window. Watermarktriggers are highlighted in the plot 600 h of FIG. 6H. A number of abusedetection pipelines run on MillWheel. Abuse detection is another exampleof a use case where processing a majority of the data quickly is muchmore useful than processing 100% of the data more slowly. As such, theyare heavy users of MillWheel's percentile watermarks, and were a strongmotivating case for being able to support percentile watermark triggersin the model.

Relatedly, a pain point with batch processing jobs is stragglers thatcreate a long tail in execution time. While dynamic rebalancing can helpwith this issue, FlumeJava has a custom feature that allows for earlytermination of a job based on overall progress. One of the benefits ofthe unified model for batch mode is that this sort of early terminationcriteria is now naturally expressible using the standard triggersmechanism, rather than requiring a custom feature.

Another pipeline considered building trees of user activity (essentiallysession trees) across multiple systems. These trees were then used tobuild recommendations tailored to users' interests. The pipeline wasnoteworthy in that it used processing-time timers to drive its output.This was due to the fact that, for their system, having regularlyupdated, partial views on the data was much more valuable than waitinguntil mostly complete views were ready once the watermark passed the endof the session. It also meant that lags in watermark progress due to asmall amount of slow data would not affect timeliness of output for therest of the data. This pipeline thus motivated inclusion ofprocessing-time triggers shown in the plots 600 c and 600 d of FIGS. 6Cand 6D, respectively.

When developing triggers, their diff detection system motivateddata-driven triggers. These differs observe the stream of queries andcalculate statistical estimates of whether a spike exists or not. Whenthey believe a spike is happening, they emit a start record, and whenthey believe it has ceased, they emit a stop. Though a technique coulddrive the differ output with something periodic like Trill'spunctuations, for anomaly detection, obtaining an output as soon as ananomaly is confidently discovered is ideal; the use of punctuationsessentially transforms the streaming system into micro-batch,introducing additional latency. While practical for a number of usecases, it ultimately is not an ideal fit for this one, thus motivatingsupport for custom data-driven triggers. It was also a motivating casefor trigger composition, because in reality, the system runs multiplediffers at once, multiplexing the output of them according to awell-defined set of logic. The AtCount trigger used in the plot 600 e ofFIG. 6E exemplified data-driven triggers; while the plots 600 f-600 j ofFIGS. 6F-6J utilized composite triggers.

The future of data processing is unbounded data. Though bounded datawill always have an important and useful place, it is semanticallysubsumed by its unbounded counterpart. Furthermore, the proliferation ofunbounded data sets across modern business is staggering. At the sametime, consumers of processed data grow savvier by the day, demandingpowerful constructs like event-time ordering and unaligned windows. Themodels and systems that exist today serve as an excellent foundation onwhich to build the data processing tools of tomorrow, but it is of firmbelief that a shift in overall mindset is necessary to enable thosetools to comprehensively address the needs of consumers of unboundeddata.

Based on many years of experience with real-world, massive-scale,unbounded data processing, the system 100 set forth above is a good stepin that direction. The system 100 supports the unaligned,event-time-ordered windows modern data consumers require, whileproviding flexible triggering and integrated accumulation andrefraction, and refocusing the approach from one of finding completenessin data to one of adapting to the ever present changes manifest inreal-world datasets. The system 100 abstracts away the distinction ofbatch vs. micro-batch vs. streaming, allowing pipeline builders a morefluid choice between them, while shielding them from the system-specificconstructs that inevitably creep into models targeted at a singleunderlying system. The overall flexibility of the system 100 allowspipeline builders to appropriately balance the dimensions ofcorrectness, latency, and cost to fit their use case, which is criticalgiven the diversity of needs in existence. And lastly, the system 100clarifies pipeline implementations by separating the notions of whatresults are being computed, where in event time they are being computed,when in processing time they are materialized, and how earlier resultsrelate to later refinements.

A software application (i.e., a software resource) may refer to computersoftware that causes a computing device to perform a task. In someexamples, a software application may be referred to as an “application,”an “app,” or a “program.” Example applications include, but are notlimited to, system diagnostic applications, system managementapplications, system maintenance applications, word processingapplications, spreadsheet applications, messaging applications, mediastreaming applications, social networking applications, and gamingapplications.

The non-transitory memory may be physical devices used to store programs(e.g., sequences of instructions) or data (e.g., program stateinformation) on a temporary or permanent basis for use by a computingdevice. The non-transitory memory may be volatile and/or non-volatileaddressable semiconductor memory. Examples of non-volatile memoryinclude, but are not limited to, flash memory and read-only memory(ROM)/programmable read-only memory (PROM)/erasable programmableread-only memory (EPROM)/electronically erasable programmable read-onlymemory (EEPROM) (e.g., typically used for firmware, such as bootprograms). Examples of volatile memory include, but are not limited to,random access memory (RAM), dynamic random access memory (DRAM), staticrandom access memory (SRAM), phase change memory (PCM) as well as disksor tapes.

FIG. 7 is a schematic view of an example computing device 700 that maybe used to implement the systems and methods described in this document.The computing device 700 is intended to represent various forms ofdigital computers, such as laptops, desktops, workstations, personaldigital assistants, servers, blade servers, mainframes, and otherappropriate computers. The components shown here, their connections andrelationships, and their functions, are meant to be exemplary only, andare not meant to limit implementations of the inventions describedand/or claimed in this document.

The computing device 700 includes a processor 710 (e.g., data storagehardware), memory 720, a storage device 730, a high-speedinterface/controller 740 connecting to the memory 720 and high-speedexpansion ports 750, and a low speed interface/controller 760 connectingto low speed bus 770 and storage device 730. Each of the components 710,720, 730, 740, 750, and 760, are interconnected using various busses,and may be mounted on a common motherboard or in other manners asappropriate. The processor 710 can process instructions for executionwithin the computing device 700, including instructions stored in thememory 720 or on the storage device 730 to display graphical informationfor a graphical user interface (GUI) on an external input/output device,such as display 780 coupled to high speed interface 740. In otherimplementations, multiple processors and/or multiple buses may be used,as appropriate, along with multiple memories and types of memory. Also,multiple computing devices 700 may be connected, with each deviceproviding portions of the necessary operations (e.g., as a server bank,a group of blade servers, or a multi-processor system). The data storagehardware 710 (e.g., processor) may execute the streaming computationsystem 100.

The memory 720 (e.g., memory hardware) stores informationnon-transitorily within the computing device 700. The memory 720 may bea computer-readable medium, a volatile memory unit(s), or non-volatilememory unit(s). The non-transitory memory 720 may be physical devicesused to store programs (e.g., sequences of instructions) or data (e.g.,program state information) on a temporary or permanent basis for use bythe computing device 500. Examples of non-volatile memory include, butare not limited to, flash memory and read-only memory (ROM)/programmableread-only memory (PROM)/erasable programmable read-only memory(EPROM)/electronically erasable programmable read-only memory (EEPROM)(e.g., typically used for firmware, such as boot programs). Examples ofvolatile memory include, but are not limited to, random access memory(RAM), dynamic random access memory (DRAM), static random access memory(SRAM), phase change memory (PCM) as well as disks or tapes.

The storage device 730 is capable of providing mass storage for thecomputing device 700. In some implementations, the storage device 730 isa computer-readable medium. In various different implementations, thestorage device 730 may be a floppy disk device, a hard disk device, anoptical disk device, or a tape device, a flash memory or other similarsolid state memory device, or an array of devices, including devices ina storage area network or other configurations. In additionalimplementations, a computer program product is tangibly embodied in aninformation carrier. The computer program product contains instructionsthat, when executed, perform one or more methods, such as thosedescribed above. The information carrier is a computer- ormachine-readable medium, such as the memory 720, the storage device 730,or memory on processor 710.

The high speed controller 740 manages bandwidth-intensive operations forthe computing device 700, while the low speed controller 760 manageslower bandwidth-intensive operations. Such allocation of duties isexemplary only. In some implementations, the high-speed controller 740is coupled to the memory 720, the display 780 (e.g., through a graphicsprocessor or accelerator), and to the high-speed expansion ports 750,which may accept various expansion cards (not shown). In someimplementations, the low-speed controller 760 is coupled to the storagedevice 730 and low-speed expansion port 770. The low-speed expansionport 570, which may include various communication ports (e.g., USB,Bluetooth, Ethernet, wireless Ethernet), may be coupled to one or moreinput/output devices, such as a keyboard, a pointing device, a scanner,or a networking device such as a switch or router, e.g., through anetwork adapter.

The computing device 700 may be implemented in a number of differentforms, as shown in the figure. For example, it may be implemented as astandard server 700 a or multiple times in a group of such servers 700a, as a laptop computer 700 b, or as part of a rack server system 700 c.

Various implementations of the systems and techniques described here canbe realized in digital electronic and/or optical circuitry, integratedcircuitry, specially designed ASICs (application specific integratedcircuits), computer hardware, firmware, software, and/or combinationsthereof. These various implementations can include implementation in oneor more computer programs that are executable and/or interpretable on aprogrammable system including at least one programmable processor, whichmay be special or general purpose, coupled to receive data andinstructions from, and to transmit data and instructions to, a storagesystem, at least one input device, and at least one output device.

These computer programs (also known as programs, software, softwareapplications or code) include machine instructions for a programmableprocessor, and can be implemented in a high-level procedural and/orobject-oriented programming language, and/or in assembly/machinelanguage. As used herein, the terms “machine-readable medium” and“computer-readable medium” refer to any computer program product,non-transitory computer readable medium, apparatus and/or device (e.g.,magnetic discs, optical disks, memory, Programmable Logic Devices(PLDs)) used to provide machine instructions and/or data to aprogrammable processor, including a machine-readable medium thatreceives machine instructions as a machine-readable signal. The term“machine-readable signal” refers to any signal used to provide machineinstructions and/or data to a programmable processor.

Implementations of the subject matter and the functional operationsdescribed in this specification can be implemented in digital electroniccircuitry, or in computer software, firmware, or hardware, including thestructures disclosed in this specification and their structuralequivalents, or in combinations of one or more of them. Moreover,subject matter described in this specification can be implemented as oneor more computer program products, i.e., one or more modules of computerprogram instructions encoded on a computer readable medium for executionby, or to control the operation of, data processing apparatus. Thecomputer readable medium can be a machine-readable storage device, amachine-readable storage substrate, a memory device, a composition ofmatter effecting a machine-readable propagated signal, or a combinationof one or more of them. The terms “data processing apparatus”,“computing device” and “computing processor” encompass all apparatus,devices, and machines for processing data, including by way of example aprogrammable processor, a computer, or multiple processors or computers.The apparatus can include, in addition to hardware, code that creates anexecution environment for the computer program in question, e.g., codethat constitutes processor firmware, a protocol stack, a databasemanagement system, an operating system, or a combination of one or moreof them. A propagated signal is an artificially generated signal, e.g.,a machine-generated electrical, optical, or electromagnetic signal, thatis generated to encode information for transmission to suitable receiverapparatus.

A computer program (also known as an application, program, software,software application, script, or code) can be written in any form ofprogramming language, including compiled or interpreted languages, andit can be deployed in any form, including as a stand-alone program or asa module, component, subroutine, or other unit suitable for use in acomputing environment. A computer program does not necessarilycorrespond to a file in a file system. A program can be stored in aportion of a file that holds other programs or data (e.g., one or morescripts stored in a markup language document), in a single filededicated to the program in question, or in multiple coordinated files(e.g., files that store one or more modules, sub programs, or portionsof code). A computer program can be deployed to be executed on onecomputer or on multiple computers that are located at one site ordistributed across multiple sites and interconnected by a communicationnetwork.

The processes and logic flows described in this specification can beperformed by one or more programmable processors executing one or morecomputer programs to perform functions by operating on input data andgenerating output. The processes and logic flows can also be performedby, and apparatus can also be implemented as, special purpose logiccircuitry, e.g., an FPGA (field programmable gate array) or an ASIC(application specific integrated circuit).

Processors suitable for the execution of a computer program include, byway of example, both general and special purpose microprocessors, andany one or more processors of any kind of digital computer. Generally, aprocessor will receive instructions and data from a read only memory ora random access memory or both. The essential elements of a computer area processor for performing instructions and one or more memory devicesfor storing instructions and data. Generally, a computer will alsoinclude, or be operatively coupled to receive data from or transfer datato, or both, one or more mass storage devices for storing data, e.g.,magnetic, magneto optical disks, or optical disks. However, a computerneed not have such devices. Moreover, a computer can be embedded inanother device, e.g., a mobile telephone, a personal digital assistant(PDA), a mobile audio player, a Global Positioning System (GPS)receiver, to name just a few. Computer readable media suitable forstoring computer program instructions and data include all forms ofnon-volatile memory, media and memory devices, including by way ofexample semiconductor memory devices, e.g., EPROM, EEPROM, and flashmemory devices; magnetic disks, e.g., internal hard disks or removabledisks; magneto optical disks; and CD ROM and DVD-ROM disks. Theprocessor and the memory can be supplemented by, or incorporated in,special purpose logic circuitry.

To provide for interaction with a user, one or more aspects of thedisclosure can be implemented on a computer having a display device,e.g., a CRT (cathode ray tube), LCD (liquid crystal display) monitor, ortouch screen for displaying information to the user and optionally akeyboard and a pointing device, e.g., a mouse or a trackball, by whichthe user can provide input to the computer. Other kinds of devices canbe used to provide interaction with a user as well; for example,feedback provided to the user can be any form of sensory feedback, e.g.,visual feedback, auditory feedback, or tactile feedback; and input fromthe user can be received in any form, including acoustic, speech, ortactile input. In addition, a computer can interact with a user bysending documents to and receiving documents from a device that is usedby the user; for example, by sending web pages to a web browser on auser's client device in response to requests received from the webbrowser.

One or more aspects of the disclosure can be implemented in a computingsystem that includes a backend component, e.g., as a data server, orthat includes a middleware component, e.g., an application server, orthat includes a frontend component, e.g., a client computer having agraphical user interface or a Web browser through which a user caninteract with an implementation of the subject matter described in thisspecification, or any combination of one or more such backend,middleware, or frontend components. The components of the system can beinterconnected by any form or medium of digital data communication,e.g., a communication network. Examples of communication networksinclude a local area network (“LAN”) and a wide area network (“WAN”), aninter-network (e.g., the Internet), and peer-to-peer networks (e.g., adhoc peer-to-peer networks).

The computing system can include clients and servers. A client andserver are generally remote from each other and typically interactthrough a communication network. The relationship of client and serverarises by virtue of computer programs running on the respectivecomputers and having a client-server relationship to each other.

In some implementations, a server transmits data (e.g., an HTML page) toa client device (e.g., for purposes of displaying data to and receivinguser input from a user interacting with the client device). Datagenerated at the client device (e.g., a result of the user interaction)can be received from the client device at the server.

While this specification contains many specifics, these should not beconstrued as limitations on the scope of the disclosure or of what maybe claimed, but rather as descriptions of features specific toparticular implementations of the disclosure. Certain features that aredescribed in this specification in the context of separateimplementations can also be implemented in combination in a singleimplementation. Conversely, various features that are described in thecontext of a single implementation can also be implemented in multipleimplementations separately or in any suitable sub-combination. Moreover,although features may be described above as acting in certaincombinations and even initially claimed as such, one or more featuresfrom a claimed combination can in some cases be excised from thecombination, and the claimed combination may be directed to asub-combination or variation of a sub-combination.

Similarly, while operations are depicted in the drawings in a particularorder, this should not be understood as requiring that such operationsbe performed in the particular order shown or in sequential order, orthat all illustrated operations be performed, to achieve desirableresults. In certain circumstances, multi-tasking and parallel processingmay be advantageous. Moreover, the separation of various systemcomponents in the embodiments described above should not be understoodas requiring such separation in all embodiments, and it should beunderstood that the described program components and systems cangenerally be integrated together in a single software product orpackaged into multiple software products.

A number of implementations have been described. Nevertheless, it willbe understood that various modifications may be made without departingfrom the spirit and scope of the disclosure. Accordingly, otherimplementations are within the scope of the following claims. Forexample, the actions recited in the claims can be performed in adifferent order and still achieve desirable results.

What is claimed is:
 1. A method comprising: receiving, at dataprocessing hardware, data corresponding to one of streaming data orbatch data; determining, using the data processing hardware, a contentof the received data for computation; determining, using the dataprocessing hardware, an event time of the data for slicing the data;determining a processing time to output results of the received datausing the data processing hardware; grouping, using the data processinghardware, a first subset of the received data into a first window, thefirst window defining a first sub-event time of the first data subset;aggregating, using the data processing hardware, a first result of thefirst data subset for the first window; and determining, by the dataprocessing hardware, a first trigger time to: emit the first aggregatedresult of the first data subset; store a copy of the first aggregatedresult in a persistent state within memory hardware; and refine a nextaggregate result of a later subset with the first aggregated result,wherein the first trigger time comprises at least one of: when awatermark reaches an end of the first window; every threshold number ofseconds of a walltime; after receiving a punctuation record thatterminates the first window; every threshold number of records; afterarbitrary user logic decides to trigger; or after an arbitrarycombination of concrete triggers.
 2. The method of claim 1, furthercomprising: grouping, using the data processing hardware, later subsetsof the received data into windows based on the event time, the windowscomprising one of: fixed windows defined by a static time period, eachfixed window applied across all of the data within the associated timeperiod; sliding windows defined by a time period and a slide period,each sliding window applied across all of the data within the associatedtime period and associated with a start time separated from a start timeof an immediately successive window by the slide period; session windowsdefined by a timeout gap, each session window applied across a subset ofthe data occurring within a span of time less than the associatedtimeout gap; or user-defined windows defined by a pair of functions. 3.The method of claim 1, further comprising: assigning, using the dataprocessing hardware, a mergable window for each element of the receiveddata, each element including an associated input timestamp and eachsession window extending a predefined range of time beyond the inputtimestamp for the associated window; merging, using the data processinghardware, two or more of the mergable windows belonging to a same keythat overlap into a single merged window; and setting, using the dataprocessing hardware, an associated output timestamp for each element toa value greater than or equal to an earliest time in the associatedmerged window or the associated mergeable window.
 4. The method of claim3, wherein the single merged window includes a range of time greaterthan the predefined range of time.
 5. The method of claim 1, furthercomprising, when the received data corresponds to streaming data:grouping, using the data processing hardware, the streaming data intowindows; setting, using the data processing hardware, an input timestampon an element of the streaming data; and when the input timestamp on theelement occurs earlier than a watermark, determining, using the dataprocessing hardware, the streaming data comprises late streaming data;and one of: dropping the late streaming data; or allowing the latestreaming data by creating a duplicate window in an output for the latestreaming data.
 6. The method of claim 1, further comprising: grouping,using the data processing hardware, a second subset of the received datainto a second window, the second window defining a second sub-event timeof the second data subset; aggregating, using the data processinghardware, a second result of the second data subset for the secondwindow; and determining, using the data processing hardware, a secondtrigger time to emit the second aggregated result of the second datasubset, the second trigger time comprising at least one of: when awatermark reaches an end of the second window; every threshold number ofseconds of a walltime; after receiving a punctuation record thatterminates the second window; every threshold number of records; afterarbitrary user logic decides to trigger; or after an arbitrarycombination of concrete triggers.
 7. The method of claim 1, furthercomprising, when determining the first trigger time to emit the firstaggregated result of the first data subset, discarding, using the dataprocessing hardware, the first aggregated result from use whenaggregating results of later subsets of the received data.
 8. The methodof claim 1, further comprising: when determining the first trigger timeto emit the first aggregated result of the first data subset, storingthe copy of the first aggregated result in the persistent state withinthe memory hardware; and when the next aggregated result of the latersubset associated with the same window emits: emitting a retraction ofthe first aggregated result; and emitting a combined session result forthe first window.
 9. The method of claim 1, further comprising:receiving, at the data processing hardware, a late data point aftergrouping the data subset into the first window, the late data pointrelated to the first window; and discarding, using the data processinghardware, the late data point.
 10. The method of claim 1, furthercomprising: receiving, at the data processing hardware, a late datapoint after grouping the first data subset into the first window, thelate data point related to the first window; and accumulating, using thedata processing hardware, the late data point into the first window torefine the first aggregated result with the late data point.
 11. Themethod of claim 1, further comprising: receiving, at the data processinghardware, a late data point after grouping the first data subset intothe first window, the late data point related to the first window;aggregating, using the data processing hardware, a combined result ofthe first data subset and the late data point; and emitting the combinedresult.
 12. A system comprising: data processing hardware; and memoryhardware in communication with the data processing hardware, the memoryhardware storing instructions that when executed on the data processinghardware cause the data processing hardware to perform operationscomprising: receiving data corresponding to one of streaming data orbatch data; determining a content of the received data for computation;determining an event time of the data for slicing the data; determininga processing time to output results of the received data; grouping afirst subset of the received data into a first window, the first windowdefining a first sub-event time of the first data subset; aggregating afirst result of the first data subset for the first window; determininga first trigger time to: emit the first aggregated result of the firstdata subset; store a copy of the first aggregated result in a persistentstate within the memory hardware; and refine a next aggregate result ofa later subset with the first aggregated result, wherein the firsttrigger time comprises at least one of: when a watermark reaches an endof the first window; every threshold number of seconds of a walltime;after receiving a punctuation record that terminates the first window;every threshold number of records; after arbitrary user logic decides totrigger; or after an arbitrary combination of concrete triggers.
 13. Thesystem of claim 12, wherein the operations further comprise groupinglater subsets of the received data into windows based on the event time,the windows comprising one of: fixed windows defined by a static timeperiod, each fixed window applied across all of the data within theassociated time period; sliding windows defined by a time period and aslide period, each sliding window applied across all of the data withinthe associated time period and associated with a start time separatedfrom a start time of an immediately successive window by the slideperiod; session windows defined by a timeout gap, each session windowapplied across a subset of the data occurring within a span of time lessthan the associated timeout gap; or user-defined windows defined by apair of functions.
 14. The system of claim 12, wherein the operationsfurther comprise: assigning a mergeable window for each element of thereceived data, each element including an associated input timestamp andeach mergeable window extending a predefined range of time beyond theinput timestamp for the associated window; merging two or more of themergeable windows belonging to a same key that overlap into a singlemerged window; and setting an associated output timestamp for eachelement to a value greater than or equal to an earliest time in theassociated merged window or the associated mergeable window.
 15. Thesystem of claim 14, wherein the single merged window includes anassociated range of time greater than the predefined range of time. 16.The system of claim 12, wherein the operations further comprise, whenthe received data corresponds to streaming data: grouping the streamingdata into windows; setting an input timestamp on an element of thestreaming data; and when the input timestamp on the element occursearlier than a watermark: determining the streaming data comprises latestreaming data; and one of: dropping the late streaming data; orallowing the late streaming data by creating a duplicate window in anoutput for the late streaming data.
 17. The system of claim 12, whereinthe operations further comprise: grouping a second subset of thereceived data into a second window, the second window defining a secondsub-event time of the second data subset; aggregating a second result ofthe second data subset for the second window; and determining a secondtrigger time to emit the second aggregated result of the second datasubset, the second trigger time comprising at least one of: when awatermark reaches an end of the second window; every threshold number ofseconds of a walltime; after receiving a punctuation record thatterminates the second window; every threshold number of records; afterarbitrary user logic decides to trigger; or after an arbitrarycombination of concrete triggers.
 18. The system of claim 12, whereinthe operations further comprise, when determining the first trigger timeto emit the first aggregated result of the first data subset, discardingthe first aggregated result from use when aggregating results of latersubsets of the received data.
 19. The system of claim 12, wherein theoperations further comprise: when determining the first trigger time toemit the first aggregated result of the first data subset, storing thecopy of the first aggregated result in the persistent state within thememory hardware; and when the next aggregated result of the later subsetassociated with the same window emits: emitting a retraction of thefirst aggregated result; and emitting a combined session result for thefirst window.
 20. The system of claim 12, wherein the operations furthercomprise: receiving a late data point after grouping the first datasubset into the first window, the late data point related to the firstwindow; and discarding the late data point.
 21. The system of claim 17,wherein the operations further comprise: receiving a late data pointafter grouping the first data subset into the first window, the latedata point related to the second window; and accumulating the late datapoint into the first window to refine the first aggregated result withthe late data point.
 22. The system of claim 17, wherein the operationsfurther comprise: receiving a late data point after grouping the firstdata subset into the first window, the late data point related to thefirst window; aggregating a combined result of the first data subset andthe late data point; and emitting the combined result.